tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Clive De Silva" <c...@dcs.qmul.ac.uk>
Subject Re: saving and opening files
Date Tue, 14 Jan 2003 22:36:13 GMT
Hi - just tried your suggestion and it returns:
I'm file2 and I am at C:\Program Files\Apache Group\Tomcat 4.1\states.gip
- and guess what, it is not there!Any other ideas? ;-)

Clive

----- Original Message -----
From: "Julius Davies" <juliusdavies@cucbc.com>
To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
Cc: <cds1@dcs.qmul.ac.uk>
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: juliusdavies@cucbc.com, Ph: 604.730.6385




> -----Original Message-----
> From: Clive De Silva [mailto:cds1@dcs.qmul.ac.uk]
> Sent: Monday, January 13, 2003 3:48 PM
> To: tomcat-user@jakarta.apache.org
> 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
>


---
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:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message