Link to home
Create AccountLog in
Avatar of ARACK04
ARACK04

asked on

file not found exception

FileInputStream toZip = new FileInputStream("dir\\" + (String)filenames.elementAt(i));

generates exception:
java.io.FileNotFoundException: dir\2.txt (The system cannot find the path specified)

I used a relative path, and from where (both) the .java and .class files are, there is a directory named  dir  with a file named  2.txt  in it.  Any ideas?

Thanks!
Avatar of Mick Barry
Mick Barry
Flag of Australia image

It is relative from where you run it
to have it relative to class file try:

InputStream toZip = getClass().getResourceAsStream("dir/" + (String)filenames.elementAt(i));
Avatar of ARACK04
ARACK04

ASKER

When you say it's relative from where I run it, is that the location of java.exe?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer