I have an object, in this object I have an InputStream which contains a file.
I want to write what is inside of InputStream to a file inside of a folder.
How would I go about doing this in Core Java?
I was able to print out each line of the InputStream using BufferedReader and .readLine(), however I want the entire file wrote to disk not just what is inside of it.
Hopefully this makes sense, thank you.
If you are using Java 7 or above you can use java.nio.file.Files:
InputStream in = obj.getInputStrem();
Path file = ...;
Files.copy(in, path);
It also supports different options (see CopyOption implementations like StandardCopyOption and LinkOption)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With