HOME       LIST

【JAVA】BufferedWriterを利用して行単位にテキストを書き込みするサンプル02

BufferedWriterを利用して行単位にテキストを書き込みするサンプル02


/*
 * 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();
                }
        }
    }
}

以前コンテンツ:【JAVA】BufferedWriterを利用して行単位にテキストを書き込みするサンプル01
次のコンテンツ:【JAVA】MDBへのODBC接続サンプル02(データソース(ODBC)設定無し)



Copyright(c) 2007-2024 dojeun.com All Rights Reserved.

Valid XHTML 1.0 Transitional