Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I used following for my highschool project long time ago. Due to my poor English skills I do not really understand what class you wish to save and load (LinkedList or myMainClass), but I used this solution to successfully store and load any of my custom objects. I hope you find it handy.</p> <p>Usage:</p> <pre><code>myMainClass object; // // ... your code fillin up the content of object // MyIO io = new MyIO(); io.save("", "myfile.dat", object); // "" as first argument will make java use current working directory // to load the object: myMainObject object = (myMainObject) io.load("", "myfile.dat"); </code></pre> <p>Source:</p> <pre><code>import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import java.io.FileOutputStream; import java.io.FileInputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.IOException; public class MyIO { // String path - path to the directory where the file is supposed to be saved. // String filename - the name of the file // Object data - object that you wish to save in the file. In your case "myMainClass" public void save(String path, String filename, Object data) { try { FileOutputStream fos = new FileOutputStream(path + filename, false); GZIPOutputStream gzos = new GZIPOutputStream(fos); ObjectOutputStream out = new ObjectOutputStream(gzos); out.writeObject(data); out.flush(); out.close(); } catch (IOException e) { System.out.println(e); } } // String path - path to the directory where the file is stored // String filename - the name of the file // The function returns java object which can be cast to myMainClass. public Object load(String path, String filename) { try { FileInputStream fis = new FileInputStream(path + filename); GZIPInputStream gzis = new GZIPInputStream(fis); ObjectInputStream in = new ObjectInputStream(gzis); Object data = in.readObject(); in.close(); return data; } catch (Exception e) { System.out.println(e); } return null; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload