Write string to output stream

后端 未结 6 856
误落风尘
误落风尘 2020-12-04 07:34

I have several output listeners that are implementing OutputStream. It can be either a PrintStream writing to stdout or to a File, or it can be writing to memory or any othe

6条回答
  •  萌比男神i
    2020-12-04 08:21

    You can create a PrintStream wrapping around your OutputStream and then just call it's print(String):

    final OutputStream os = new FileOutputStream("/tmp/out");
    final PrintStream printStream = new PrintStream(os);
    printStream.print("String");
    printStream.close();
    

提交回复
热议问题