FileReader类读取指定字符;
一个字符一个字符往外读,可以读出中文
import java.io.*;
public class TestFileReader {
public static void main(String args[]){
FileReader Read = null;
int c=0;
try{
Read =new FileReader("d:\\logs.txt");
//int In = 0;
while ((c=Read.read())!=-1){
System.out.println((char)c);
}
Read.close();
}catch (FileNotFoundException e){
System.out.println("找不到指定文件");
}catch (IOException e1){
System.out.println("文件读取错误");
}
}
}
FileReader类写入字符;
未找到在指定路径下自动创建;
import java.io.*;
public class TestFileWriter {
public static void main(String args[]){
FileWriter wr =null;
try {
wr = new FileWriter("d:\\logs1.txt");
for(int c=0;c<=50000;c++){
wr.write(c);
}
wr.close();
}catch (IOException e2){
e2.printStackTrace();
System.out.println("文件写入错误");
System.exit(-1);
}
}
}