FileOutputStream構造方法中的第二個參數
FileOutputStream fos = new FileOutputStream(destfile,true);中,第二個參數加上以后程序好像一直循環(huán)了,本來1k的txt文件一會兒就幾個G了,不明白哪里會導致一直循環(huán);代碼:
FileInputStream fis = new FileInputStream(srcfile);
??FileOutputStream fos = new FileOutputStream(destfile,true);
??byte[] buf = new byte[20*1024];
??int b=0;
??//從fis中讀取數據存放到buf,從0位置開始,讀取最長buf.length個字節(jié)
??while((b = fis.read(buf, 0, buf.length))!=0)
??{
???//將buf的內容寫入fos,從0位置開始,最多寫入b個字節(jié)
???fos.write(buf, 0, buf.length);
???fos.flush();
??}
2017-11-06
true是什么意思啊
2016-10-31
FileInputStream?fis?=?new?FileInputStream(srcfile); ??FileOutputStream?fos?=?new?FileOutputStream(destfile,true); ??byte[]?buf?=?new?byte[20*1024]; ??int?b=0; ??//從fis中讀取數據存放到buf,從0位置開始,讀取最長buf.length個字節(jié) ??while(!(b?=?fis.read(buf,?0,?buf.length))=-1)//循環(huán)條件是讀到-1結束 ??{ ???//將buf的內容寫入fos,從0位置開始,最多寫入b個字節(jié) ???fos.write(buf,?0,?buf.length); ???fos.flush(); ??}2016-10-08
應該是while()條件里面的不等于-1吧,你寫的是0
2016-09-14
2016-08-15
? fos.write(buf, 0, buf.length);中的buf.length改為b
2016-07-19
隱藏問題
2016-07-19
循環(huán)條件寫錯了,至于刪除問題,你可以試一下在回答中輸入“隱藏問題”命令。。。
2016-07-11
找到錯誤了,,粗心寫錯了
有沒有人知道怎么把問題刪除嗎……