1.单个字符方式
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("读取文件位置");
FileWriter fw = new FileWriter("输出文件位置");
int ch;
while ((ch = fr.read()) != -1){
System.out.println(((char) ch));
}
fr.close();
fw.close();
}
2.字符数组方式
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("读取文件位置");
FileWriter fw = new FileWriter("输出文件位置");
char[] cbuf = new char[1024];
int len;
while ((len = fr.read(cbuf)) != -1){
fw.write(new String(cbuf,0,len));
}
fw.flush();
fr.close();
fw.close();
}