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



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM