Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Database {
- public static void saveStudentsToFile(File file, Student[] students) throws IOException{
- if(file==null || students==null){
- throw new IllegalArgumentException();
- }
- try(ObjectOutput oos = new ObjectOutputStream(new FileOutputStream(file))){
- oos.writeObject(students);
- }catch (IOException e){
- throw e;
- }
- }
- public static Student[] loadStudentsFromFile(File file) throws ClassNotFoundException, IOException{
- if(file == null){
- throw new IllegalArgumentException("NO FILE");
- }
- Student[] students = null;
- try(ObjectInput ois = new ObjectInputStream(new FileInputStream(file))){
- students = (Student[])ois.readObject();
- }catch (IOException e){
- throw e;
- }catch (ClassNotFoundException e){
- throw e;
- }
- return students;
- }
- }
Add Comment
Please, Sign In to add comment