hi!
I m using netbeans 6.5.1 i am trying to read a text file from a jsp using the code

BufferedReader input = new BufferedReader(new FileReader("contactus.txt"));

this file "contactus.txt" is placed in the same folder (ie web folder) as the jsp file. but the browser is giving the error
file not found. pls help.....
i m not sure where the txt file should be placed in netbeans project to make it find it or should i try a different way to give url?

Recommended Answers

All 2 Replies

Welcome memegha123.

getRealPath() translate a local URL into a path name in the local file system.

String path=application.getRealPath("/contactus.txt");
BufferedReader input = new BufferedReader(new FileReader(path));

thanx a lot it seems to work i m no longer getting that exception file not found

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.