When to use which Writer subclass in Java; common practices

后端 未结 4 743
执念已碎
执念已碎 2021-02-07 03:40

I have always been slightly confused with the amount of different IO implementations in Java, and now that I am completely stuck in my project development, I was taking my time

4条回答
  •  面向向阳花
    2021-02-07 03:53

    You can create an appending PrintWriter like this:

    OutputStream os = new FileOutputStream("/tmp/out", true);
    PrintWriter writer = new PrintWriter(os);
    

    Edit: Anon's post is right about both using a BufferedWriter in between and specifying the encoding.

提交回复
热议问题