Advertisement
Guest User

Untitled

a guest
Aug 17th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. public class Layout implements Serializable {
  2.  
  3. private String username;
  4. private String password;
  5. public String getUsername() {
  6. return username;
  7. }
  8. public void setUsername(String username) {
  9. this.username = username;
  10. }
  11. public String getPassword() {
  12. return password;
  13. }
  14. public void setPassword(String password) {
  15. this.password = password;
  16. }
  17.  
  18. public Layout(){
  19. username="";
  20. password="";
  21. }
  22. public Layout(String user,String pass){
  23. username=user;
  24. password=pass;
  25. }
  26. @Override
  27. public String toString() {
  28. return "Match Found! [Username: " + username + ", Password: " + password+"]";
  29. }
  30.  
  31. int i;
  32. Layout[] items = new Layout[1];
  33.  
  34. CrunchifySerializeDeserialize c = new CrunchifySerializeDeserialize();
  35. for (i = 0; i < items.length; i++) {
  36.  
  37. items[i] = c.new Layout();
  38. }
  39.  
  40.  
  41. String a = JOptionPane.showInputDialog("Enter Username");
  42. String b = JOptionPane.showInputDialog("Enter Password");
  43. items[0].setUsername(a);
  44. items[0].setPassword(b);
  45.  
  46.  
  47. System.out.println("Personal info Details.....");
  48. for (Layout d : items) {
  49. System.out.print(d.getUsername());
  50. System.out.print("t" + d.getPassword());
  51. }
  52.  
  53. List<Layout> obj;
  54. obj = new ArrayList<Layout>();
  55.  
  56. for (i = 0; i < items.length; i++) {
  57. obj.add(items[i]);
  58. }
  59. items=new Layout[1];
  60.  
  61. try {
  62.  
  63. ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("./Test1.txt",true));
  64. out.writeObject(obj);
  65.  
  66. out.close();
  67.  
  68. System.out.println("nSerialization Successful... Checkout your specified output file..n");
  69.  
  70. } catch (FileNotFoundException e) {
  71. e.printStackTrace();
  72. } catch (IOException e) {
  73. e.printStackTrace();
  74. }
  75.  
  76. try {
  77. //FileInputStream fileIn = new FileInputStream("./Crunchify_Test1.txt");
  78. ObjectInputStream in = new ObjectInputStream(new FileInputStream("./Test1.txt"));
  79. boolean check = true;
  80. while(check){
  81. try{
  82. System.out.println("Deserialized Data: n" + in.readObject().toString());
  83. //reinitailize shit
  84.  
  85. }catch(EOFException e){
  86. check=false;
  87. }
  88. }
  89. //System.out.println("Deserialized Data: n" + in.readObject().toString());
  90.  
  91. in.close();
  92. //fileIn.close();
  93. } catch (FileNotFoundException e) {
  94. e.printStackTrace();
  95. } catch (IOException e) {
  96. e.printStackTrace();
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement