You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Clive De Silva <cd...@dcs.qmul.ac.uk> on 2003/01/14 00:48:24 UTC

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