Java 字节流读写文件

import java.io.*;
class Test{
public static void main(String args[]){
FileInputStream fis = null;
FileOutputStream fos = null;
byte[] buffer = new byte[100];
int temp = 0;
try{
fis = new FileInputStream("D:/wenhao/src/from.txt");
fos = new FileOutputStream("D:/wenhao/src/to.txt");
while(true){
temp = fis.read(buffer,0,buffer.length);
if(temp == -1){
break;
}
fos.write(buffer,0,temp);
}
}
catch(Exception e){
System.out.println(e);
}
finally{
try{
fis.close();
fos.close();
}
catch(Exception e2){
System.out.println(e2);
}
}

}
}
posted @ 2011-12-25 11:16  hnrainll  阅读(15838)  评论(0编辑  收藏  举报