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