Can I use both PrintWriter and BufferedOutputStream on the same outputstream?

前端 未结 3 952
傲寒
傲寒 2021-01-23 07:58

Can I use both PrintWriter and BufferedOutputStream on the same outputstream?

The situation is this:

I\'m having a SSLSocket program and I want to be able to tra

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-23 08:09

    PrintWriter is just a wrapper around original OutputStream. BufferedOutputStream is a wrapper around OutputStream too. So you can use both. Why not?

    Single thing you should to consider - you should be carefull working with both stream and writer in multithread environment because you can get unpredictable result.

    The java.io.Writer class (super class for PrintWriter) use itself as a lock object. So you can also probably use it to synchronize multiple threads.

提交回复
热议问题