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 Overflowjava - How to convert FileInputStream to InputStream? - Stack Overflow
Why is my fileinputstream not working ?
Best way to convert Inputstream to Multipartfile
FileNotFoundException thrown when I am trying to mock the ObjectMapper object so that I could run the Unit Test without an actual file
Videos
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;
InputStream is = new FileInputStream("c://filename");
return is;
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 !