Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read File from relative path using FileInputStream

I want to read a file from a relative path. I've tried the following code

InputStream in = new FileInputStream(".//Audio//w1.wav");

Error:

java.io.FileNotFoundException: .\Audio\w1.wav (The system cannot find the path specified)

I also tried to specify the path as "Audio/w1.wav", "Audio//w1.wav" but it does not work.

How can I get the system to find the file?

like image 477
अक्षय परूळेकर Avatar asked May 12 '26 22:05

अक्षय परूळेकर


1 Answers

The problem seems to be a wrong path. To track that down, start with figuring out where . is. To do so run:

System.out.println(new File(".").getAbsolutePath());

This should print the entire path you're in, beginning with c:\ or / depending on your os.

Now take a look at that folder in the explorer, is everything you expect to be in . in that folder?

  • If yes: check for typos and switch between \ and / and check file access permissions?
  • If no: adjust your path or move the files.
like image 149
Poohl Avatar answered May 14 '26 12:05

Poohl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!