aspose file tools
The moose likes Servlets and the fly likes trouble finding a text file to read into an array Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "trouble finding a text file to read into an array" Watch "trouble finding a text file to read into an array" New topic
Author

trouble finding a text file to read into an array

Jim Bauer
Greenhorn

Joined: Nov 07, 2005
Posts: 9
I'm having trouble reading a text file from a couple of classes that are served up from servlets via jsp.
What I'm doing is reading the file into an array and building from there.

String fileread = "bauerquarterhorses.com\\Combined.txt";
LoadArray2 newarray = new LoadArray2();
newarray.SetArray(fileread);

I've moved my Combined.txt file all over and it can't seem to find it.

It works fine on my machine. But I have to specify where on my c: drive to look for the file. How do I get the class on the web site to know where to look?

any help would be appreciated!!

Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If the file is within your web applications folder hierarchy the best method is ServletContext.getResourceAsStream.
java.lang.String)" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getResourceAsStream(java.lang.String)


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: trouble finding a text file to read into an array
 
Similar Threads
Merging 2 xml files and want to see the output how can I achieve.
reading a .txt file to load objects into an array
Really Challenging...HelpMe..java.Util - very Urgent
Non syncronized output even when accessing syncronized method
Page Not Found Error w/ JSP