jdk11和jdk1.8 readAllBytes方法
File qrFile = new File("./结婚证二维码.png"); FileInputStream in = new FileInputStream(qrFile); byte[] imageBuffer = in.readAllBytes(); //jdk11 处理方式 //@@ jdk1.8处理方式 byte[] imageBuffer = Files.readAllBytes(Paths.get("结婚证合影.png"));
另外一个例子
1 static String GetFileBase64(String fileName) { 2 try { 3 FileInputStream in = new FileInputStream(fileName); 4 // byte[] fileBuffer = in.readAllBytes(); //jdk11处理方式 5 byte[] fileBuffer = Files.readAllBytes(Paths.get(fileName));//@@ jdk8处理方式
参考
JAVA IO总结:归纳从文件中读取数据的六种方法https://blog.csdn.net/weixin_48182198/article/details/108382025