35 lines
790 B
Plaintext
35 lines
790 B
Plaintext
package com.sercurityControl.proteam.util;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.util.Base64;
|
|
|
|
/**
|
|
* @ClassName FileToBase64
|
|
* @Description
|
|
* @Author Fclever
|
|
* @Date 2021/8/11 13:46
|
|
**/
|
|
public class FileToBase64 {
|
|
|
|
/**
|
|
* 将文件转为Base64值
|
|
*
|
|
* @param file 文件对象
|
|
* @return
|
|
*/
|
|
public static String convertToBase64(File file) {
|
|
byte[] fileBytes = null;
|
|
FileInputStream fis = null;
|
|
try {
|
|
fis = new FileInputStream(file);
|
|
fileBytes = new byte[(int) file.length()];
|
|
fis.read(fileBytes);
|
|
fis.close();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return Base64.getEncoder().encodeToString(fileBytes);
|
|
}
|
|
}
|