mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2025-06-07 06:14:04 +08:00
扩展FileUtil
This commit is contained in:
parent
b97fdf65bc
commit
8741562463
@ -285,7 +285,17 @@ public class FileUtil {
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static String base64(File file) {
|
||||
public static String base64ToStr(File file) {
|
||||
return new String(base64(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件base64
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static byte[] base64(File file) {
|
||||
FileInputStream fileInputStream = null;
|
||||
byte[] data = null;
|
||||
// 读取图片字节数组
|
||||
@ -299,12 +309,22 @@ public class FileUtil {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 对字节数组Base64编码
|
||||
return new String(Base64.getEncoder().encode(data));
|
||||
return Base64.getEncoder().encode(data);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = base64(new File("Z:\\NAS\\04.coding\\yexuejc\\yexuejc-base"));
|
||||
System.out.printf( s);
|
||||
/**
|
||||
* base64转文件
|
||||
* <p>
|
||||
* <i>
|
||||
* 文件转base64请使用 {@link FileUtil#base64(File)}
|
||||
* </i>
|
||||
*
|
||||
* @param decode {@link FileUtil#base64ToStr(File)} 的结果
|
||||
* @param fileName 文件名称(包含路径)
|
||||
* @return 返回保存地址
|
||||
*/
|
||||
public static String base64ToFile(String decode, String fileName) {
|
||||
return base64ToFile(Base64.getDecoder().decode(decode.getBytes()), fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user