流技术读写文件
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class TestFileInputStream{
public static void main(String[] args){
InputStream in =null;
OutputStream out = null;
try{
in = new FileInputStream("D:\\java\\TestFileInputStream.java");
out = new FileOutputStream("D:\\TestFileInputStream.java");
} catch(FileNotFoundException e){
System.out.println("找不到指定文件");
System.exit(-1);
}
try{
long num = 0;
int b = 0;
while((b=in.read()) != -1){
out.write(b);
System.out.print((char) b);
num++;
}
in.close();
System.out.println();
System.out.println("共读了:"+num+"个字符");
}catch(IOException e1){
System.out.println("文件读取错误");
System.exit(-1);
}
}
}
posted on 2010-10-31 10:38 sail out to sea 阅读(142) 评论(0) 编辑 收藏 举报