It actually depends on the servlet engine/java environment. You can
check it by calling
String defaultPath = System.getProperty("user.dir");
Some engines default to a nice place where servlets will have correct
permissions to read/write. Other engines don't. One example is JServ
which seems to default to making user.dir be "/"!
In general, it seems like reading from the place pointed to by
"user.dir" is good for servlets. It kills platform independence to use
absolute paths to files, and making a user set init arguments just isn't
always possible (especially if they aren't the admin on a machine).
Therefore, a directory that servlets can always read/write to seems to
make a lot of sense. In our own servlets on coolservlets.com, we use
"user.dir"... if anyone has better ideas, we'd love to hear them! Also,
it would be good to find out why JServ defaults to using "/"...
Thanks!
-Matt Tucker
"G. Naik" wrote:
>
> just curious...where would a servlet default to opening a file without an
> absolute path....ie
>
> BufferedReader in = new BufferedReader(new FileReader(blah.db));
> StreamTokenizer inStream = new StreamTokenizer(in);
>
> I am having trouble with those lines of code. It is throwing
> exceptions...Any ideas...
>
> -g-
>
> At 02:26 PM 4/25/99 -0700, you wrote:
> >> However, I am not sure
> >>if servlets can open up text files on the local server, and if this is
> >>feasible.
> >
> >Sure it's possible and feasible. We just finished a prototype as a prelude
> >to using a relational database. We used a simple random access file, opened
> >in the init method, saved in a global variable, accessed in the doPost
> >method (see below). Simple, even primitive, but it works. Our biggest
> >problem was figuring out what directory on our hosted site our servlet was
> >expecting to find the file.
> >
> >Regards,
> >Steve Mann
> >
> ># # #
> >
> >// in init
> >
> > gDataFile = new RandomAccessFile ( gDataFileName, "r" );
> >
> >// In doPost
> >
> > gDataFile.seek ( 0 );
> > long filePtr = 0;
> > while ( filePtr < gDataFile.length ()) {
> > line = gDataFile.readLine ();
> > // do something.....
> > filePtr = gDataFile.getFilePointer ();
> > }
> >
> >-------------------------------------------
> >Creative Digital Publishing Inc.
> >1317 Palm Street, San Luis Obispo, CA 93401-3117
> >-------------------------------------------
> >805.788.0138 805.593.3811 (fax)
> >[EMAIL PROTECTED] http://www.cdpubs.com
> >
> >___________________________________________________________________________
> >To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> >of the message "signoff SERVLET-INTEREST".
> >
> >Archives: http://archives.java.sun.com/archives/servlet-interest.html
> >Resources: http://java.sun.com/products/servlet/external-resources.html
> >LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> >
> >
> --
> [ G. Naik http://www.message-server.com ]
> [ Carroll-Net Inc. "NJ's Premier Internet Service Provider" ]
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
--
-------------------------------
Matt Tucker
[EMAIL PROTECTED]
http://cs.uiowa.edu/~matucker
See CoolServlets:
http://www.coolservlets.com
-------------------------------
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html