Guest User

Untitled

a guest
May 16th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public class Main {
  2. private static ArrayList<User> users = new ArrayList<User>();
  3.  
  4. @SuppressWarnings("unchecked")
  5. public static void main(String[] args) {
  6. users = (ArrayList<User>) deserData("users");
  7. User user = new User();
  8. user.setName(JOptionPane.showInputDialog(null, "Login:"));
  9. user.setSurname(JOptionPane.showInputDialog(null, "Password:"));
  10. users.add(user);
  11. for (User p : users) {
  12. System.out.println(p.getName() + " " + p.getSurname());
  13. }
  14.  
  15. serData("users", users);
  16. }
  17.  
  18. private static Object deserData(String file_name) {
  19. Object retObject = null;
  20. try {
  21. FileInputStream fileIn = new FileInputStream(file_name + ".ser");
  22. ObjectInputStream in = new ObjectInputStream(fileIn);
  23. retObject = in.readObject();
  24. fileIn.close();
  25. in.close();
  26. } catch (FileNotFoundException e) {
  27. System.out.println("File is Not Found");
  28. System.exit(1);
  29. } catch (IOException e) {
  30. System.out.println("Intit Output error");
  31. System.exit(2);
  32. } catch (ClassNotFoundException e) {
  33. System.out.println("Class is Not Found");
  34. System.exit(3);
  35. }
  36. return retObject;
  37. }
  38. }
Add Comment
Please, Sign In to add comment