Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void saveToStorageFile() throws IOException {
- System.out.println("saveToStorageStart() started!");
- FileOutputStream fos = new FileOutputStream(new File("SiteDataStorage"));
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- //Prints the List
- for(int i = 0 ; i < this.size(); i++) {
- System.out.println("Save list:" + this.db.get(i).getText());
- }
- SiteData[] siteData = db.toArray(new SiteData[db.size()]);
- //Prints the sitedata array length
- System.out.println(siteData.length);
- oos.writeObject(siteData);
- oos.close();
- System.out.println("Saved!");
- }
- import java.io.*;
- import java.util.*;
- class SiteData implements Serializable {
- public static void main(String[] args) throws Throwable {
- new SiteData().saveToStorageFile();
- }
- private int size() { return 1; } // Did you not want db?
- private List<SiteData> db = List.of(this);
- private String getText() { return "Some text"; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement