0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

FileWriter class

Posted at

FileWriterにてfile writeができる。
BufferedWriterを使うことによりまとまった単位での書き込み
flushはメモリとファイルの同期をとる
FileWriterのsecond argumentはappendするか否か

public class Outer {
    public static void main(String[] args) {
        try {
            FileWriter fw = new FileWriter("C:\\dirtest\\testwritefile.txt",true);
            BufferedWriter bw = new BufferedWriter(fw);
            try(bw) {
                bw.write("hello");
                bw.newLine();
                bw.write("my fiend");
                bw.newLine();
                bw.flush();
            } 
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?