Advertisement
Guest User

Untitled

a guest
Aug 21st, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.Collections;
  4.  
  5.  
  6.  
  7. public class consoleArray{
  8.    
  9.  
  10.     private ArrayList<Console> consoleArray = new ArrayList<Console>();    
  11.    
  12.     public void add(Console thisOne){
  13.         consoleArray.add(thisOne);
  14.     }
  15.    
  16.     public void sortName(){
  17.         Collections.sort(consoleArray, new sortByName());
  18.     }
  19.    
  20.     public void list(){
  21.         for(Console temp : consoleArray){
  22.             System.out.println(temp.getName());
  23.         }
  24.     }
  25.    
  26.     public void save(){
  27.         try{  
  28.  
  29.             FileOutputStream saveFile = new FileOutputStream("SaveConsoles.sav");
  30.             ObjectOutputStream save = new ObjectOutputStream(saveFile);
  31.  
  32.             save.writeObject(consoleArray);
  33.  
  34.             saveFile.close();
  35.             save.close();
  36.         }
  37.         catch (FileNotFoundException exc){         
  38.             exc.printStackTrace();
  39.         }
  40.         catch (IOException exc){
  41.             exc.printStackTrace();
  42.         }
  43.     }
  44.  
  45.     public void restore(){
  46.        
  47.         try{   
  48.             FileInputStream fis = new FileInputStream("SaveConsoles.sav");
  49.             ObjectInputStream ois = new ObjectInputStream(fis);
  50.             Object obj = ois.readObject();
  51.             ArrayList<Console> consoleArray = (ArrayList<Console>) obj;
  52.         }
  53.         catch (FileNotFoundException exc){         
  54.             exc.printStackTrace();
  55.         }
  56.         catch (IOException exc){
  57.             exc.printStackTrace();
  58.         }
  59.         catch (ClassNotFoundException exc){
  60.             exc.printStackTrace();
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement