java例程练习(字符流)

2014-11-24 07:53:53 · 作者: · 浏览: 0

import java.io.*;

public class TestFileReader {
public static void main(String[] args) {
FileReader fr = null;
int c = 0;
try {
fr = new FileReader("C:/java/Test.java");

while((c = fr.read()) != -1) {
System.out.print((char)c);
}
fr.close();
} catch (FileNotFoundException e) {
System.out.println("找不到指定文件");
} catch (IOException e) {
System.out.println("文件读取错误");
}
}
}
[java]
import java.io.*;


public class TestFileWriter {
public static void main(String[] args) {
FileWriter fw = null;

try {
fw = new FileWriter("C:/java/unicode.txt");
for(int c = 0; c <= 50000; c++) {
fw.write(c);
}
fw.close();
} catch (IOException e) {
System.out.println(e.getMessage());
System.out.println("文件写入错误");
System.exit(-1);
}
}
}


摘自 Yours风之恋