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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值