JavaでBufferedWriterクラスを利用してファイルに書き込むサンプル

Javaコード
package com.startnews24.fileoper;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class FileWriteDemo {
public static void main(String[] args) {
try {

String content = “start to write content to file";

File file = new File(“/www/data/startnews24study_file.txt");
if (!file.exists()) {
file.createNewFile();
}

FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();

System.out.println(“write finished");

} catch (IOException e) {
e.printStackTrace();
}
}
}

Java

Posted by arkgame