텍스트파일에 그냥 쓰기
FileWriter writer = new FileWriter("ReadAndWrite.txt");
writer.write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n");
writer.write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n");
writer.write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n");
writer.write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n");
writer.close();
텍스트파일에 버퍼를 사용하여 쓰기
FileWriter fileWriter = new FileWriter("ReadAndWrite.txt");
BufferedWriter writer = new BufferedWriter(fileWriter);
writer.write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n");
writer.write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n");
writer.write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n");
writer.write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n");
writer.close();
텍스트파일을 버퍼를 이용하여 읽기
FileReader fileReader = new FileReader("ReadAndWrite.txt");
BufferedReader reader = new BufferedReader(fileReader);
String line = null;
while((line = reader.readLine()) != null ) {
System.out.println(line);
}
reader.close();
햇갈리지 말자!
객체를 저장할때는
objectOutputStream.writeObject(someObject);
String을 저장할때는
fileWriter.write("하고싶은말");