Avatar of dkim18
 asked on

The system cannot find the path specified error

Hi Experts,

I am trying to read input file like this...

dis = new DataInputStream(new FileInputStream("org//xxx//xxx//xxx//resources//"+ boyFilenames[type]));

and I am getting this error:
 java.io.FileNotFoundException: org\xxx\xxx\xxx\resources\xxx.txt (The system cannot find the path specified)

When I run the above program by itself, it works fine.
I made jar file for the above program and stored in ...WEB-INF/lib/ dir and run a J2ee app, it doesn't work.

thanks in advance

Is this co
JavaJava EE

Avatar of undefined
Last Comment

8/22/2022 - Mon

On what operating system you are executing it in either case?
Is it windows or unix ?

You should not do double splashes for unix system - direct slashes should not be escaped.
Only on windows back slashes should be escaped.



You probably need something more like
dis = new DataInputStream(getClass().getResourceAsStream("/org/xxx/xxx/xxx/resources/" + boyFilenames[type]));

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy


I am still getting the same error when I run the web app.

>>I am still getting the same error when I run the web app.

You can't have applied the code i gave you effectively - it won't throw that exception

Do you have the files in the same loaction as your classes?
if you file is in WEB-INF/classes/org/....

then you should have it without first slash like they show it in

InputStream csv =

In your case it should be:

DataInputStream in =
   SomeClassInTheSamePackage.class.getResourceAsStream(org/xxx/xxx/xxx/resources/" + boyFilenames[type]));

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

so, do I need to modify in different ways?

Please post the listing of the jar in WEB-INF/lib
jar tf thejar.jar

Open in new window


try removing first slash from /org..., assuming that your org is in WEB-INF/classes

Please, explain where your filese really are located
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes

In fact it would be better to attach the file listing.txt with
jar tf thejar.jar >listing.txt

Open in new window


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

This operator :
getClass().getResourceAsStream("org/xxx/xxx/xxx/resources/" + boyFilenames[type]);

refers to the location of your current class where you have this statement - so it will start looking at your files eitherr from the location where
your class (current class or you can explicitly name like in that link
 SomeClassInTheSamePackage.class.getResourceAsStream("org/xxx/xxx/xxx/resources/" + boyFilenames[type]);)

Then starting from the folder where the class referered in this operator is sitting (either
with WEB-INF/classes structure or in your jar file) from that point it will be looking for your
folder org/xxx/xxx/xxx/resources/ and then for files inside that folder.

So check if the files are there, and if they are it should work

Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.