FileOutputStream을 이용한 파일 생성 및 쓰기
public static void main(String[] args) throws IOException {
FileOutputStream out = new FileOutputStream("d:/out.txt");
for(int i=1; i<6;i++){
String texts = i + "번 라인\n";
out.write(texts.getBytes());
}
out.close();
}
FileWriter을 이용한 파일 생성 및 쓰기
public static void main(String[] args) throws IOException {
FileWriter out = new FileWriter("d:/out.txt");
for(int i=1; i<6;i++){
String texts = i + "번 라인\n";
out.write(texts);
}
out.close();
}
PrintWriter을 이용한 파일 생성 및 쓰기
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter("d:/out.txt");
for(int i=1; i<6;i++){
String texts = i + "번 라인";
out.println(texts);
}
out.close();
}