Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Collections;
- public class consoleArray{
- private ArrayList<Console> consoleArray = new ArrayList<Console>();
- public void add(Console thisOne){
- consoleArray.add(thisOne);
- }
- public void sortName(){
- Collections.sort(consoleArray, new sortByName());
- }
- public void list(){
- for(Console temp : consoleArray){
- System.out.println(temp.getName());
- }
- }
- public void save(){
- try{
- FileOutputStream saveFile = new FileOutputStream("SaveConsoles.sav");
- ObjectOutputStream save = new ObjectOutputStream(saveFile);
- save.writeObject(consoleArray);
- saveFile.close();
- save.close();
- }
- catch (FileNotFoundException exc){
- exc.printStackTrace();
- }
- catch (IOException exc){
- exc.printStackTrace();
- }
- }
- public void restore(){
- try{
- FileInputStream fis = new FileInputStream("SaveConsoles.sav");
- ObjectInputStream ois = new ObjectInputStream(fis);
- Object obj = ois.readObject();
- ArrayList<Console> consoleArray = (ArrayList<Console>) obj;
- }
- catch (FileNotFoundException exc){
- exc.printStackTrace();
- }
- catch (IOException exc){
- exc.printStackTrace();
- }
- catch (ClassNotFoundException exc){
- exc.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement