Efficient way to write InputStream to a File in Java 6

后端 未结 3 680
忘掉有多难
忘掉有多难 2021-02-15 02:52

I will get input stream from third party library to my application. I have to write this input stream to a file.

Following is the code snippet I tried:

p         


        
3条回答
  •  隐瞒了意图╮
    2021-02-15 03:18

    If you're not on Java 7 and can't use fge's solution, you may want to wrap your OutputStream in a BufferedOutputStream

    BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream("xx.txt"));
    

    Such buffered output stream will write bytes in blocks to the file, which is more efficient than writing byte per byte.

提交回复
热议问题