aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
jQuery in Action, 2nd edition
 
subject: Read file from current dir in webserver
 
Similar Threads
JBOSS
Creating a file
Not able to start with Tomcat
Reading the file
files