You need to create new file and copy contents from InputStream to that file:

File file = //...
try(OutputStream outputStream = new FileOutputStream(file)){
    IOUtils.copy(inputStream, outputStream);
} catch (FileNotFoundException e) {
    // handle exception here
} catch (IOException e) {
    // handle exception here
}

I am using convenient IOUtils.copy() to avoid manual copying of streams. Also it has built-in buffering.

Answer from Tomasz Nurkiewicz on Stack Overflow
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ api โ€บ java โ€บ io โ€บ FileInputStream.html
FileInputStream (Java Platform SE 8 )
April 21, 2026 - Javaโ„ข Platform Standard Ed. 8 ... A FileInputStream obtains input bytes from a file in a file system.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java io โ€บ java โ€“ convert file to inputstream
Java - Convert File to InputStream | Baeldung
January 5, 2024 - @Test public void givenUsingCommonsIO_whenConvertingFileToInputStream_thenCorrect() throws IOException { File initialFile = new File("src/main/resources/sample.txt"); InputStream targetStream = FileUtils.openInputStream(initialFile); } And there we have it. Three simple and clean solutions for opening a stream from a Java file. In this article, we explored various ways to convert a File to InputStream by using different libraries.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_fileinputstream.asp
Java FileInputStream
FileInputStream - best for binary data (images, audio, PDFs) or when you need full control of raw bytes. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com ยท HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-io-fileinputstream-class-java
Java FileInputStream Class - GeeksforGeeks
November 3, 2025 - Creates an input file stream to read from a file with the specified name.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java io โ€บ java โ€“ write an inputstream to a file
Java - Write an InputStream to a File | Baeldung
August 20, 2025 - How to convert an InputStream to a byte[] using plain Java, Guava or Commons IO. ... @Test public void whenConvertingToFile_thenCorrect() throws IOException { Path path = Paths.get("src/test/resources/sample.txt"); byte[] buffer = java.nio.file.Files.readAllBytes(path); File targetFile = new File("src/test/resources/targetFile.tmp"); OutputStream outStream = new FileOutputStream(targetFile); outStream.write(buffer); IOUtils.closeQuietly(outStream); }
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ examples โ€บ load-file-as-inputstream
Java Program to Load File as InputStream
We then used the read() method to read all the data from the file. ... We can also load this Java file as input stream. import java.io.InputStream; import java.io.FileInputStream; public class Main { public static void main(String args[]) { try { // file Test.java is loaded as input stream ...
Find elsewhere
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ how to convert inputstream to file in java
How to convert InputStream to File in Java - Mkyong.com
December 27, 2020 - In Java 9, we can use the new InputStream#transferTo to copy the InputStream to an OutputStream directly.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 278406 โ€บ java โ€บ Writing-input-stream-file
Writing input stream to file (I/O and Streams forum at Coderanch)
February 15, 2007 - I know how to get the InputStream ... the file. Can anyone help me? ... All you need to do is open an output stream (presumably a FileOutputStream in your case), read from the input stream and write to the output stream. Have a look at the Java tutorial chapter on IO...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ implement-how-to-load-file-as-inputstream-in-java
Implement how to load File as InputStream in Java - GeeksforGeeks
July 23, 2025 - The read() method of InputStream class, reads a byte of data from the input stream. The next byte of data is returned, or -1 if the end of the file is reached and throws an exception if an I/O error occurs.
๐ŸŒ
Medium
medium.com โ€บ @praveenraovp01 โ€บ input-streams-in-java-613a953f730c
Input Streams in Java!. A stream in Java can be defined as aโ€ฆ | by PraveenLearnsStuff | Medium
May 6, 2023 - And, the object input stream to read the object from the file. Note: The Dog class implements the Serializable interface. It is because the ObjectOutputStream only writes the serializable objects to the output stream, which we will cover in another article! ... I hope this article gives an idea about the implementation of InputStream in Java 8 and above.
๐ŸŒ
Initial Commit
initialcommit.com โ€บ blog โ€บ java-convert-inputstream-to-file
Java โ€“ Convert InputStream to File
July 11, 2018 - public static void convertInpu... nio packages exposed by Java 8, you can write an InputStream to a File using Files.copy() utility method....
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ fileinputstream
Java FileInputStream (With Examples)
The FileInputStream class of the java.io package can be used to read data (in bytes) from files. It extends the InputStream abstract class.
๐ŸŒ
Medium
medium.com โ€บ javarevisited โ€บ fileinputstream-and-fileoutputstream-in-java-a-guide-to-reading-and-writing-files-f46cb8a648a3
FileInputStream and FileOutputStream in Java: A Guide to Reading and Writing Files | by WhatInDev | Javarevisited | Medium
December 21, 2024 - The java.io.FileInputStream class is used for reading the contents of a file in Java. It provides methods to read byte data from a file, making it suitable for reading binary files such as images, audio files, and other non-textual data.
๐ŸŒ
TraceDynamics
tracedynamics.com โ€บ java-file-to-inputstream
Java File To InputStream: Bridging File Data, Stream Processing
December 19, 2023 - Output: InputStream is: java.io.FileInputStream@15db9742 ยท As per output, the program reads a text file and converts a File to an InputStream.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 278228 โ€บ java โ€บ InputStream-file-absolute-path
how to get InputStream from a file with absolute path? (I/O and Streams forum at Coderanch)
October 12, 2006 - It just keeps giving me null for "is": String absFilePath = "/D:/my_dir/.../sample_file.txt"; InputStream is = getClass().getResourceAsStream(absFilePath); regards, ... I believe you should read the API Javadoc about getResourceAsStream(String name) Now, while you do that, I believe that since you already have the full path to the file it is simpler to say: Does this help?
๐ŸŒ
Jenkov
jenkov.com โ€บ tutorials โ€บ java-io โ€บ fileinputstream.html
Java FileInputStream
August 28, 2019 - The Java FileInputStream class, java.io.FileInputStream, makes it possible to read the contents of a file as a stream of bytes. The Java FileInputStream class is a subclass of Java InputStream.
๐ŸŒ
Coderunbox
coderunbox.com โ€บ example โ€บ example.java โ€บ load-file-as-inputstream
Java Program to Load File as InputStream | CodeRunBox - Code Example
To understand this example, you should have the knowledge of the following Java programming topics: ... import java.io.InputStream; import java.io.FileInputStream; public class Main { public static void main(String args[]) { try { // file input.txt is loaded as input stream // input.txt file contains: // This is a content of the file input.txt InputStream input = new FileInputStream("input.txt"); System.out.println("Data in the file: "); // Reads the first byte int i = input.read(); while(i != -1) { System.out.print((char)i); // Reads next byte from the file i = input.read(); } input.close(); } catch(Exception e) { e.getStackTrace(); } } }
๐ŸŒ
Medium
dimaspriyandi.medium.com โ€บ tips-for-using-java-streams-for-file-input-output-f553799852e5
Tips for Using Java Streams for File Input/Output | by Dimas Priyandi | Medium
July 21, 2024 - Output Stream: Used to write data to a destination. This could be a file, array, peripheral device, or socket. The flow for an input stream is illustrated below: ... Java byte stream are used to perform input and output of 8-bit bytes.