Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. package MyDictionary;
  2.  
  3. import MyDictionary.*;
  4. import java.io.*;
  5. import java.util.Enumeration;
  6.  
  7. /*A small test program for my HashMap*/
  8. public class Probl3 implements Serializable{
  9.  
  10. private static Object loadObject(){
  11.  
  12. Object aux = new Object();
  13. FileInputStream fileIn;
  14. ObjectInputStream in;
  15. try {
  16. fileIn = new FileInputStream("seria.ser");
  17. in = new ObjectInputStream(fileIn);
  18. aux = in.readObject();
  19. fileIn.close();
  20. in.close();
  21. return aux;
  22. }
  23. catch (FileNotFoundException e) {
  24. e.printStackTrace();
  25. }
  26. catch (IOException e) {
  27. e.printStackTrace();
  28. }
  29. catch (ClassNotFoundException e) {
  30. e.printStackTrace();
  31. }
  32. return aux;
  33.  
  34. }
  35.  
  36.  
  37. private static void saveObject(DicitonarIntf l) {
  38. try {
  39. FileOutputStream fileOut = new FileOutputStream("seria.ser");
  40. ObjectOutputStream out = new ObjectOutputStream(fileOut);
  41. out.writeObject(l);
  42. out.flush();
  43. fileOut.close();
  44. out.close();
  45.  
  46. }
  47. catch (FileNotFoundException e) {
  48. e.printStackTrace();
  49. }
  50. catch (IOException e) {
  51. e.printStackTrace();
  52. }
  53.  
  54. }
  55.  
  56. public static void main(String[] args) throws ApplicationException, IOException {
  57. DicitonarIntf hm = new HashMap();
  58. //HashMap h=new HashMap();
  59. try
  60. {
  61. BufferedReader br = new BufferedReader(new FileReader("test.txt"));
  62. String strLine;
  63. strLine = br.readLine();
  64.  
  65.  
  66. //hm.put(strLine, "=a pleca");
  67. //hm.put("pleca", "= a parasi, a renunta");
  68. //hm.put("manca", "= a infuleca, a se hrani");
  69. //hm.put("renunta", "= a nu mai face");
  70. //hm.put("scrie", "= a interpreta ceva");
  71. String q = "key";
  72. String t = "pleca";
  73. Iterator it = ((HashMap)hm).keySet().getIterator();
  74. while (it.hasNext())
  75. System.out.println(it.next());
  76. System.out.println();
  77. hm.put("rezolva", "= o noua interpretare");
  78. System.out.println(hm.get("manc"));
  79. System.out.println();
  80. hm.remove("manca");
  81. hm.remove(t);
  82.  
  83. //saveObject(hm);
  84. Object HashMap;
  85.  
  86. DicitonarIntf l=(HashMap)loadObject();
  87. Iterator it1 = ((HashMap)l).keySet().getIterator();
  88. while (it.hasNext())
  89. System.out.println(it.next());
  90.  
  91. //implementare exceptie
  92. int i=-9;
  93. ((HashMap)hm).setTSize(i);
  94.  
  95. //
  96. //it = ((HashMap)hm).keySet().getIterator();
  97. // while (it.hasNext())
  98. // System.out.println(it.next(q));
  99.  
  100.  
  101. System.out.println("test");
  102.  
  103.  
  104. //serialization
  105.  
  106. }
  107. catch (FileNotFoundException e) {
  108. e.printStackTrace();
  109. } catch (IOException e) {
  110. e.printStackTrace();
  111.  
  112. }
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement