I *think* a file with a relative path is usually put into the directory from
which the JVM is started.
(that's what I've found so far - don't know if it's *always* true)

Well, anyway: "File" has a method "getAbsolutePath()" (or something like
that).

Just let the file tell you where it is :-)

File file2 = new java.io.File("states.gip");
System.out.println("I'm file2 and I am at " + file2.getAbsolutePath());

HTH - Good luck!


> -----Urspr�ngliche Nachricht-----
> Von: Clive De Silva [mailto:[EMAIL PROTECTED]]
> Gesendet: Dienstag, 14. Januar 2003 01:17
> An: Tomcat Users List
> Cc: Julius Davies
> Betreff: Re: saving and opening files
> 
> 
> Hi, I did that and the path was: C:\Program Files\Apache 
> Group\Tomcat 4.1
> 
> but the file is not there!!!!!
> 
> Ideas?
> 
> ----- Original Message -----
> From: "Julius Davies" <[EMAIL PROTECTED]>
> To: "Tomcat Users List" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Tuesday, January 14, 2003 12:08 AM
> Subject: RE: saving and opening files
> 
> 
> 
> Clive De Silva,
> 
> I may be wrong, but I think your file would be here:
> 
> System.getProperty( "user.dir" );
> 
> That should output a string showing the directory where your 
> files will be
> put by default.  This is because you specified a relative path -- new
> java.io.File("states.gip") -- not an absolute path.
> 
> You can call 'System.getProperty( "user.dir" )' at anytime 
> from anywhere in
> your application, even a jsp.
> 
> yours,
> 
> Julius Davies, Programmer, CUCBC
> Email: [EMAIL PROTECTED], Ph: 604.730.6385
> 
> 
> 
> 
> > -----Original Message-----
> > From: Clive De Silva [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, January 13, 2003 3:48 PM
> > To: [EMAIL PROTECTED]
> > Subject: saving and opening files
> >
> >
> > Hi, I have placed my package in the \Apache Group\Tomcat
> > 4.1\common\classes\ folder and they are all standard Java
> > classes [no servlets or jsps]. One of the methods invoked in
> > my main class serializes an object and saves it to a
> > persistent file at runtime :
> >
> > ---------------------Start Snip 1-----------------------
> >   public boolean saveUser(){
> >     File file2 = new java.io.File("states.gip");
> >       try{
> >         myUser.allocateUser(user);
> >         FileOutputStream out2 = new FileOutputStream(file2);
> >         ObjectOutputStream s2 = new ObjectOutputStream(out2);
> >         s2.writeObject(myUser);
> >         s2.flush();
> >         System.out.println("You have save successfully");
> >         return true;
> >       }
> >       catch(Exception e){
> >         e.printStackTrace();
> >         System.out.println("You have save UN-Successfully");
> >         return false;
> >       }
> >   }
> > ---------------------End Snip 1-----------------------
> >
> > When the class is initialised/created, it first checks to see
> > if there is a file called states.gip and if there is, then it
> > reads in the object, if there isnt, then it creates an object
> > and at a latter stage saves it:
> >
> > ---------------------Start Snip 2-----------------------
> >   public boolean createUser(String name){
> >     try{//see if a user had been created and try to load it back
> >       File file2 = new java.io.File("states.gip");
> >       FileInputStream in = new FileInputStream(file2);
> >       ObjectInputStream s1 = new ObjectInputStream(in);
> >       myUser = (MainUser)s1.readObject();
> >       user = recommenderEPG.addUser(name);
> >       user = myUser.unallocate(user);
> >       System.out.println("There was an old user!");
> >       return true;
> >     }
> >     catch(Exception e){//user has not been created so an
> > exception is thrown -going to create a new user
> >       try{
> >         myUser = new MainUser(name);
> >         user = recommenderEPG.addUser(name);
> >         myUser.allocateUser(user);
> >         System.out.println("there is definitely no old user");
> >         return true;
> >       }
> >       catch (DataNotFoundException ef){
> >         return false;
> >       }
> >     }
> > ---------------------End Snip 2-----------------------
> >
> > When the class does get created for the first time, it does
> > not see the 'states.gip' file, which is correct, because it
> > has not been created yet. If it is instantiated for a second
> > or nth time, it always sees the file and loads it correctly.
> > My Question is: where is this file stored? I can not find a
> > physical trace of this file - i have done search after search
> > and it is not there - yet the Java class opens it 
> correcly!!!!! Help!
> >
> >
> > Regards,
> >
> > Clive
> >
> >
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.435 / Virus Database: 244 - Release Date: 30/12/2002
> >
> 
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> 
> 
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.435 / Virus Database: 244 - Release Date: 31/12/2002
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> 

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to