Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- private static ArrayList<User> users = new ArrayList<User>();
- @SuppressWarnings("unchecked")
- public static void main(String[] args) {
- users = (ArrayList<User>) deserData("users");
- User user = new User();
- user.setName(JOptionPane.showInputDialog(null, "Login:"));
- user.setSurname(JOptionPane.showInputDialog(null, "Password:"));
- users.add(user);
- for (User p : users) {
- System.out.println(p.getName() + " " + p.getSurname());
- }
- serData("users", users);
- }
- private static Object deserData(String file_name) {
- Object retObject = null;
- try {
- FileInputStream fileIn = new FileInputStream(file_name + ".ser");
- ObjectInputStream in = new ObjectInputStream(fileIn);
- retObject = in.readObject();
- fileIn.close();
- in.close();
- } catch (FileNotFoundException e) {
- System.out.println("File is Not Found");
- System.exit(1);
- } catch (IOException e) {
- System.out.println("Intit Output error");
- System.exit(2);
- } catch (ClassNotFoundException e) {
- System.out.println("Class is Not Found");
- System.exit(3);
- }
- return retObject;
- }
- }
Add Comment
Please, Sign In to add comment