1. java. fileReader and FileWriter: BufferedReader: cached input streams; BufferedWriter: cached output streams; FileReader: Input streams that read content from files; FileWriter: the output stream of the content written to the file. Note: The Buffered buffer zone is a kind of thing like a pool. It is filled with water and taken away at one time. Instead of taking a spoonful, this reduces the number of I/O reads and writes. 2. instance-read and write files:
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class FileBR { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader rd=new BufferedReader(new FileReader("D:\\csdn.txt")); FileWriter fw=new FileWriter("D:\\pwd.txt"); BufferedWriter bw=new BufferedWriter(fw); String tempString = ""; while((tempString=rd.readLine())!=null){ System.out.println(tempString); bw.write(tempString); bw.newLine(); bw.flush(); } } }