为什么么有时候会出现复制的文件特别大的情况?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | public class Piture { public static void main(String[] args) { try { FileInputStream fis= new FileInputStream( "G:\\File\\1.png" ); FileOutputStream fos= new FileOutputStream( "G:\\File\\12.png" ); byte [] b= new byte [ 128 ]; int n= 0 ; while ((n=fis.read(b))!= 1 ) { fos.write(b); } fis.close(); fos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } |
3
收起
正在回答 回答被采纳积分+1
2回答
彤宝贝
2019-05-24 00:19:48
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | public class Piture { public static void main(String[] args) { try { FileInputStream fis= new FileInputStream( "G:\\File\\1.png" ); FileOutputStream fos= new FileOutputStream( "G:\\File\\12.png" ); byte [] b= new byte [ 128 ]; int n= 0 ; while ((n=fis.read(b))!= 1 ) { fos.write(b, 0 ,n); } fis.close(); fos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } |
我这样写的话保证了文件大小的一致性,并且能完整的复制粘贴图片,为什么还出现异常了呢?
1. Java 零基础入门
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧