/* * BufferedWriterを利用して行単位にテキストを書き込みするサンプル02 */ package test_FileControl; import java.io.*; public class Test_FileWrite03 { public static void main(String[] args) { //ファイル指定 File file = new File("d:\\temp\\temp.txt"); OutputStream os = null; Writer w = null; BufferedWriter bw = null; try{ os = new FileOutputStream(file); w = new OutputStreamWriter(os,"MS932"); bw = new BufferedWriter(w); String wrkStr1 = "test"; bw.write(wrkStr1); bw.newLine(); bw.flush(); }catch(Exception e){ throw new RuntimeException(e); }finally{ if(bw != null) try { bw.close(); } catch (IOException e) { e.printStackTrace(); } if(w != null) try{ w.close(); }catch(IOException e){ e.printStackTrace(); } if(os != null) try{ os.close(); }catch(IOException e){ e.printStackTrace(); } } } }