import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
public class FileRAndW {
public static void main(String[] args) throws Exception {
FileWriter fileWriter = new FileWriter("hello2.txt");
fileWriter.write("这是一个拼钱的年代……");
//千万记得这里需要调用close,或者调用flush方法,否者数据不会写入文件中,因为写到了内存缓存区中
fileWriter.close();
File file = new File("hello2.txt");
if(file.exists())
{
FileReader fileReader = new FileReader("hello2.txt");
char [] buffer = new char[1024];
int len = fileReader.read(buffer);
System.out.println(new String(buffer, 0, len));
fileReader.close();
}
}
}