This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Read file from current dir in webserver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Read file from current dir in webserver" Watch "Read file from current dir in webserver" New topic
Author

Read file from current dir in webserver

michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
hi,
I am using tomcat webserver and I am having difficulty reading files. It seems that by default it read from C drive everytime i execute a servlet. How do i make it read file from current dir the servlet execute? For example WEB-INF\classes\myclass
Thanks
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
No by default it reads from /WEB-INF/classes folder. please send your code to better understand the problem.
michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
Below is part of the code in web-inf/classes/PM. If take away the file from c drive it doesn't work but when put it back it works. What are the explanation for this? Thanks
package PM;
import java.net.*;
import java.io.*;
public class week{

try{
FileInputStream istream = new FileInputStream("do.txt");
Kunaal A Trehan
Ranch Hand

Joined: Feb 04, 2004
Posts: 63
Hi
Why donot u use servelet context.
Then u can read the data as input stream
Eg.
ServLetContext contx=Session.getServletContext();
InputStream inptStr = contx.getResourceAsStream("WEB-INF/IO/FILENAME")
For this u need to put the file in some directory under WEB-INF folder
I hope this helps
Rgds
Kunal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read file from current dir in webserver
 
Similar Threads
Creating a file
Reading the file
Not able to start with Tomcat
files
JBOSS