Guest User

Untitled

a guest
Feb 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public class Database {
  2. public static void saveStudentsToFile(File file, Student[] students) throws IOException{
  3. if(file==null || students==null){
  4. throw new IllegalArgumentException();
  5. }
  6. try(ObjectOutput oos = new ObjectOutputStream(new FileOutputStream(file))){
  7. oos.writeObject(students);
  8. }catch (IOException e){
  9. throw e;
  10. }
  11. }
  12. public static Student[] loadStudentsFromFile(File file) throws ClassNotFoundException, IOException{
  13. if(file == null){
  14. throw new IllegalArgumentException("NO FILE");
  15. }
  16. Student[] students = null;
  17. try(ObjectInput ois = new ObjectInputStream(new FileInputStream(file))){
  18. students = (Student[])ois.readObject();
  19. }catch (IOException e){
  20. throw e;
  21. }catch (ClassNotFoundException e){
  22. throw e;
  23. }
  24. return students;
  25. }
  26. }
Add Comment
Please, Sign In to add comment