InputStream is;

try {
    is = new FileInputStream("c://filename");

    is.close(); 
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

return is;
Answer from Kumar Vivek Mitra on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › io › FileInputStream.html
FileInputStream (Java Platform SE 8 )
April 21, 2026 - FileInputStream is meant for reading streams of raw bytes such as image data.
🌐
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.
Discussions

java - How to convert FileInputStream to InputStream? - Stack Overflow
FileInputStream is an inputStream. More on stackoverflow.com
🌐 stackoverflow.com
Why is my fileinputstream not working ?
First of all, as other people are hinting at, the code you've posted doesn't compile because \ is an escape character in Java strings. If you want to actually put a backslash character into the string, you need to double it up like \\. If you fix that and it still doesn't work, I suspect you've simply made a mistake in the path string. One thing that jumps out at me is that in a typical Windows installation, your personal files would normally be stored under C:\Users\ricky, not C:\ricky. When in doubt, you can try modifying your code to give you more detailed information about what's going on. For example, you could try printing out the list of files in your target directory, and see if test.txt shows up as expected; File directory = new File("C:\\ricky\\...\\fileInputStream"); String[] directoryContents = directory.list(); System.out.println("Listing directory contents:"); for (String entry : directoryContents) { System.out.println(entry); } System.out.println("Found " + directoryContents.length + " entries."); More on reddit.com
🌐 r/learnprogramming
6
0
September 14, 2022
Best way to convert Inputstream to Multipartfile
Data Brokers don't stand a chance because I mass delete all of my content using Redact - No AI training on my data, thank you very much. fuel shelter arrest mountainous cats boat divide stocking different humor More on reddit.com
🌐 r/SpringBoot
7
10
December 18, 2024
FileNotFoundException thrown when I am trying to mock the ObjectMapper object so that I could run the Unit Test without an actual file
Sometimes it gets funny with mocks. Instead of new File in the readFile try Mockito.any() More on reddit.com
🌐 r/javahelp
14
2
March 17, 2024
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-io-fileinputstream-class-java
Java FileInputStream Class - GeeksforGeeks
November 3, 2025 - The FileInputStream class in Java is used to read data from a file in the form of bytes. It’s ideal for reading binary data such as images or audio files.
🌐
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.
🌐
GitHub
github.com › openjdk › jdk › blob › master › src › java.base › share › classes › java › io › FileInputStream.java
jdk/src/java.base/share/classes/java/io/FileInputStream.java at master · openjdk/jdk
* A {@code FileInputStream} obtains input bytes · * from a file in a file system. What files · * are available depends on the host environment. * * <p>{@code FileInputStream} is meant for reading streams of raw bytes · * such as image data.
Author   openjdk
Find elsewhere
🌐
CloudBees
cloudbees.com › blog › fileinputstream-fileoutputstream-considered-harmful
FileInputStream / FileOutputStream Considered Harmful
March 24, 2017 - Every time you create either a FileInputStream or a FileOutputStream you are creating an object, even if you close it correctly and promptly, it will be put into a special category that only gets cleaned up when the garbage collector does a full GC.
🌐
CodeGym
codegym.cc › java blog › java io & nio › input/output in java. fileinputstream, fileoutputstream, ...
Input/output in Java. FileInputStream, FileOutputStream, and BufferedInputStream classes
October 11, 2023 - Its constructor takes an instance of the InputStream class or any of its descendants, so FileInputStream will do. As an additional argument, it takes the buffer size in bytes. Thanks to this argument, the data will now be read from the file not one byte at a time, but 200 bytes at a time!
🌐
W3Schools
w3schools.com › java › java_ref_fileinputstream.asp
Java FileInputStream Reference
The FileInputStream class provides methods to read data (as bytes) from a file: Java I/O Streams Tutorial · Java FileInputStream Tutorial · ❮ Previous Next ❯ · ★ +1 · Sign in to track progress · REMOVE ADS · PLUS · SPACES · GET ...
🌐
BMC
docs.bmc.com › xwiki › bin › view › Mainframe › DevX › BMC-Compuware-iStrobe-Web › bcistrobew2010 › Module-Help › java-io-FileInputStream
java.io.FileInputStream - BMC Documentation
February 7, 2022 - The FileInputStream class, which inherits from the InputStream class, reads data one byte at a time. This means that if a file contains one million bytes of data, then a FileInputStream object must perform at least one million reads before the entire contents of the file are read.
🌐
Javadoc.io
javadoc.io › doc › com.googlecode.jinahya › ocap › 1.2 › java › io › FileInputStream.html
FileInputStream - ocap 1.2 javadoc
Bookmarks · Latest version of com.googlecode.jinahya:ocap · https://javadoc.io/doc/com.googlecode.jinahya/ocap · Current version 1.2 · https://javadoc.io/doc/com.googlecode.jinahya/ocap/1.2 · package-list path (used for javadoc generation -link option) · https://javadoc.io/doc/com.go...
🌐
Reddit
reddit.com › r/learnprogramming › why is my fileinputstream not working ?
r/learnprogramming on Reddit: Why is my fileinputstream not working ?
September 14, 2022 -

i have this code right here:

    import java.io.*; 
    public class Introduction {
      public static void main(String[] args) throws IOException {
        String path = "C:\ricky\Java\JavaProjects\javaStudy\fileInputStream\test.txt";
        FileInputStream fis = new FileInputStream(path);
        int i = 0; 
        while((i = fis.read()) != -1){
          System.out.print((char)i);
        }
        fis.close();
      }
    }

the file of test.txt is right here in my folder with everything else:

https://imgur.com/a/B61xK7V

However, I am getting this error right here:

    Exception in thread "main" java.io.FileNotFoundException: fileInputStream\test.txt (The system cannot find the path specified)
            at java.base/java.io.FileInputStream.open0(Native Method)
            at java.base/java.io.FileInputStream.open(FileInputStream.java:216)
            at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
            at java.base/java.io.FileInputStream.<init>(FileInputStream.java:111)
            at Introduction.main(Introduction.java:5)

i am not understanding as to how the:

    (The system cannot find the path specified)

when it's literally in the same folder that the code is in ? am i missing something simple ?

ive tried to do my due dilligence before asking by looking at these links:

https://www.reddit.com/r/javahelp/comments/2km01n/cant_get_fileinputstream_to_work/

https://www.reddit.com/r/javahelp/comments/gyphgp/why_wont_this_simple_java_file_reader_program_work/

(all of them were talking about the location of the file not being in the right place but mine is literally in the same folder of where the .java is in)

TIA !

Top answer
1 of 5
2
First of all, as other people are hinting at, the code you've posted doesn't compile because \ is an escape character in Java strings. If you want to actually put a backslash character into the string, you need to double it up like \\. If you fix that and it still doesn't work, I suspect you've simply made a mistake in the path string. One thing that jumps out at me is that in a typical Windows installation, your personal files would normally be stored under C:\Users\ricky, not C:\ricky. When in doubt, you can try modifying your code to give you more detailed information about what's going on. For example, you could try printing out the list of files in your target directory, and see if test.txt shows up as expected; File directory = new File("C:\\ricky\\...\\fileInputStream"); String[] directoryContents = directory.list(); System.out.println("Listing directory contents:"); for (String entry : directoryContents) { System.out.println(entry); } System.out.println("Found " + directoryContents.length + " entries.");
2 of 5
1
It seems you may have included a screenshot of code in your post " Why is my fileinputstream not working ? ". If so, note that posting screenshots of code is against r/learnprogramming 's Posting Guidelines (section Formatting Code): please edit your post to use one of the approved ways of formatting code . (Do NOT repost your question! Just edit it.) If your image is not actually a screenshot of code, feel free to ignore this message. Automoderator cannot distinguish between code screenshots and other images. Please, do not contact the moderators about this message. Your post is still visible to everyone. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Java-success
java-success.com › home › 00: top 50+ core java interview questions & answers – q01 – q10
Top 50+ Core Java interview questions & answers
June 1, 2025 - 50+ Core Java interview questions & answers for 1 to 3 years experience with code, examples & diagrams to prepare for Java job interviews
🌐
Programiz
programiz.com › java-programming
Learn Java Programming
Java FileInputStream Class · Java FileOutputStream Class · Java ByteArrayInputStream Class · Java ByteArrayOutputStream Class · Java ObjectInputStream Class · Java ObjectOutputStream Class · Java BufferedInputStream Class · Java BufferedOutputStream Class ·
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java › io › fileinputstream
Read file with FileInputStream - Java Code Geeks
October 26, 2013 - With this example we are going to demonstrate how to read a File with a FileInputStream. The FileInputStream obtains input bytes from a file in a file system.
🌐
W3Schools
w3schools.com › java › java_files_read.asp
Java Read Files
FileInputStream - best for binary data (images, audio, PDFs) or when you need full control of raw bytes.
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-fileinputstream-and-objectinputstream-in-java
Difference Between FileInputStream and ObjectInputStream in Java - GeeksforGeeks
July 19, 2022 - FileInputStream class extracts input bytes from a file in a file system. FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader.