java.io.Writer.write()で文字列を書き込むサンプル

2019年3月10日

サンプルコード

package com.arkgame;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class BufferedWriterDemo {

	public static void main(String[] args) {
		try {
			File fname = new File("c:/data/changfa.txt");
			OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(fname), "UTF-8");
			BufferedWriter bdr = new BufferedWriter(osw);

			bdr.write("test line1 dataAA\n");
			bdr.write("test line2 dataBB\n");
			bdr.write("test line3 dataCC");

			bdr.close();
		} catch (IOException e) {
			System.out.println(e);
		}
	}
}

Java

Posted by arkgame