import sun.misc.BASE64Encoder;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class Test2 {
public static void main(String[] args) throws IOException {
//本地图片
File file = new File("C:\\Users\\111\\Pictures\\123.jpg");
System.out.println(file.getName());
FileInputStream inputFile = new FileInputStream(file);
byte[] buffer = new byte[(int) file.length()];
inputFile.read(buffer);
inputFile.close();
String s = new BASE64Encoder().encode(buffer);
System.out.println("data:image/" + "jpg" + ";base64," + s);
}
}
Java文件转base64
最新推荐文章于 2024-04-30 08:22:51 发布