Java使用BufferedWriter实现TXT文件写入功能

public class Result{
	
	private static BufferedWriter bw;
	
	public static void init() {
		try {
			Result.bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(Properties.resultFilePath)),"UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static void writeToFile(String content) {
		try {
			bw.write(content);
			bw.newLine();
			bw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

 

你可能感兴趣的:(Java,文件操作)