Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. package shit;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.ObjectInputStream;
  7. import java.io.ObjectOutputStream;
  8. import java.io.Serializable;
  9. import java.util.Date;
  10. import java.util.Vector;
  11.  
  12. public class Task implements Serializable{
  13.  
  14. private String client;
  15. private String user;
  16. private String description;
  17. private Date issue_start;
  18. private String status;
  19. private Date issue_end;
  20.  
  21. public Task (String client, String user, String description, Date issue_start, String status, Date issue_end) {
  22. this.client = client;
  23. this.user = user;
  24. this.description = description;
  25. this.status = status;
  26. this.issue_start = issue_start;
  27. this.issue_end = issue_end;
  28. this.status = status;
  29. }
  30.  
  31. public static final String file = "C:\\Users\\Hawk\\Downloads\\krystian.txt";
  32.  
  33. public Vector<Task> tasks = new Vector<Task>();
  34.  
  35. public void addTask(Task x) {
  36. tasks.add(x);
  37. }
  38.  
  39. public void flushTask(Client task) {
  40. tasks.remove(task);
  41. }
  42. public void clearTask() {
  43. tasks.clear();
  44. }
  45. public void showTask() {
  46. System.out.println("PC is containg: ");
  47. for (Task task : tasks) {
  48. System.out.println(task + " ");
  49. }
  50.  
  51. }
  52.  
  53. public void save() throws IOException {
  54.  
  55. ObjectOutputStream oos = null;
  56. FileOutputStream fout = null;
  57. try {
  58. fout = new FileOutputStream(file, false);
  59. oos = new ObjectOutputStream(fout);
  60. oos.writeObject(tasks);
  61. } catch (Exception ex) {
  62. ex.printStackTrace();
  63. } finally {
  64. if (oos != null) {
  65. oos.close();
  66. }
  67. }
  68.  
  69. }
  70.  
  71. public void load() throws IOException, ClassNotFoundException {
  72. FileInputStream fis = new FileInputStream(file);
  73. ObjectInputStream ois = new ObjectInputStream(fis);
  74.  
  75. tasks = (Vector<Task>)ois.readObject();
  76.  
  77. ois.close();
  78. }
  79. @Override
  80. public String toString() {
  81. // TODO Auto-generated method stub
  82. return user;
  83. }
  84.  
  85.  
  86. }
  87.  
  88.  
  89.  
  90. public class main {
  91.  
  92. public static void main(String[] args) throws IOException, ClassNotFoundException {
  93. // TODO Auto-generated method stub
  94. Task x = new Task("xd3", "xddd3","wtf",new Date(), "lol", new Date());
  95. x.addTask(x);
  96. x.load();
  97. x.showTask();
  98. }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement