0

Possible Duplicate:
How to delete stuff printed to console by System.out.println()?

I have a Pickle class that serializes a linked list of words and word counts. Everything works, except that the console doesn't clear when I save and load the data. Even when I leave eclipse and run the program again, the old console output appears along with the new output. Is there anyway to clear the console before loading the object data? Here is my save method:

void save(T obj){
    try{
        FileOutputStream fos = new FileOutputStream(filename);
        ObjectOutputStream out = new ObjectOutputStream(fos);
        out.writeObject(obj);
        out.close();
    }catch(Exception e){
        System.err.println(e);
        System.exit(1);
    }
}

and my load method:

T load(){
    try{
        FileInputStream fis = new FileInputStream(filename);
        ObjectInputStream in = new ObjectInputStream(fis);
        temp = (T) in.readObject();
        return temp;
    }catch(FileNotFoundException f){
        System.err.println("Warning! File Not Found. Null is returned");
        System.exit(1);
        return null;
    } catch (Exception e) {
        System.err.println(e);
        System.exit(1);
        return null;
    }
}
Community
  • 1
  • 1
nickhirakawa
  • 247
  • 1
  • 12

1 Answers1

0

I came across this problem before. It's quite a doozy. I was able to do it by using a free/open source library called JLine http://jline.sourceforge.net/ It is quite a nice library and has support for Unix and Windows terminals including entering passwords. It also has a "clearScreen()" method to clear the screen.

I suggest you use JLine and see if it suites your needs. I can assure you that its a nice library and I'm sure you'll find its other features useful.

george_h
  • 1,562
  • 2
  • 19
  • 37