Hey there, I've made a little program which reads program data from a .ser file. The program also gives the option to save back new data into the file.
The problem is, when I JAR the program through eclipse, and run the JAR... it creates the .ser files outside of the JAR.
Is there anyway I can have the file be stored inside the JAR so It gives the program better portability?
I'm aware of accessing a file through getClass().getResourceAsStream(FILENAME), but I don't know how to therefore make it save the file inside the JAR, if that makes sense .
Here's my read from file method:
@SuppressWarnings("unchecked") public ArrayList<HoursOfTheWeek> readTableModel() { ArrayList<HoursOfTheWeek> al = null; try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(FILENAME)); al = (ArrayList<HoursOfTheWeek>) ois.readObject(); } catch (Exception e) { System.out.println("Problem reading back table from file: " + FILENAME); } if(al == null){ storeTableModel(defaultData()); readTableModel(); } return al; }
And here's my store to file method:
public void storeTableModel(ArrayList<HoursOfTheWeek> al) { ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(new FileOutputStream(FILENAME)); oos.writeObject(al); } catch (Exception e) { e.printStackTrace(); } try { oos.close(); } catch (IOException e) { } }
Thanks in advance.