System.out.println( new String( b ) );
is.close();
OutputStream os = new FileOutputStream( "D:/b.txt" );
os.write( b );
os.close();
is.close();
OutputStream os = new FileOutputStream( "D:/b.txt" );
os.write( b );
os.close();
2015-04-04
File atxt = new File( "D:/a.txt" );
InputStream is = new FileInputStream( atxt );
byte[] b = new byte[is.available()];
is.read( b );
int len = 0;
while ( ( len = is.read() ) != -1 ) {
is.read( b, 0, len );
}
System.out.println( new String( b ) );
is.close();
InputStream is = new FileInputStream( atxt );
byte[] b = new byte[is.available()];
is.read( b );
int len = 0;
while ( ( len = is.read() ) != -1 ) {
is.read( b, 0, len );
}
System.out.println( new String( b ) );
is.close();
2015-04-04
我覺得應該直接寫 fr.read(buffer) 比 fr.read(buffer,0,buffer.length) 更好,感覺 buffer.length 是多余的
2015-03-30
我覺得flush()寫在while循環外比較好,flush()是將未滿的緩存送出去,保證傳輸的完整性,寫在while內的話,buffer流就相當于單字節傳輸方式,不是一個緩存一個緩存的送出去,效率變低了,buffer只有緩存沒滿而恰好文件讀取完成時才要用到flush(),所以寫在buffer的close()之前就好,不用寫在while內
2015-03-21