Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MyDictionary;
- import MyDictionary.*;
- import java.io.*;
- import java.util.Enumeration;
- /*A small test program for my HashMap*/
- public class Probl3 implements Serializable{
- private static Object loadObject(){
- Object aux = new Object();
- FileInputStream fileIn;
- ObjectInputStream in;
- try {
- fileIn = new FileInputStream("seria.ser");
- in = new ObjectInputStream(fileIn);
- aux = in.readObject();
- fileIn.close();
- in.close();
- return aux;
- }
- catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- return aux;
- }
- private static void saveObject(DicitonarIntf l) {
- try {
- FileOutputStream fileOut = new FileOutputStream("seria.ser");
- ObjectOutputStream out = new ObjectOutputStream(fileOut);
- out.writeObject(l);
- out.flush();
- fileOut.close();
- out.close();
- }
- catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) throws ApplicationException, IOException {
- DicitonarIntf hm = new HashMap();
- //HashMap h=new HashMap();
- try
- {
- BufferedReader br = new BufferedReader(new FileReader("test.txt"));
- String strLine;
- strLine = br.readLine();
- //hm.put(strLine, "=a pleca");
- //hm.put("pleca", "= a parasi, a renunta");
- //hm.put("manca", "= a infuleca, a se hrani");
- //hm.put("renunta", "= a nu mai face");
- //hm.put("scrie", "= a interpreta ceva");
- String q = "key";
- String t = "pleca";
- Iterator it = ((HashMap)hm).keySet().getIterator();
- while (it.hasNext())
- System.out.println(it.next());
- System.out.println();
- hm.put("rezolva", "= o noua interpretare");
- System.out.println(hm.get("manc"));
- System.out.println();
- hm.remove("manca");
- hm.remove(t);
- //saveObject(hm);
- Object HashMap;
- DicitonarIntf l=(HashMap)loadObject();
- Iterator it1 = ((HashMap)l).keySet().getIterator();
- while (it.hasNext())
- System.out.println(it.next());
- //implementare exceptie
- int i=-9;
- ((HashMap)hm).setTSize(i);
- //
- //it = ((HashMap)hm).keySet().getIterator();
- // while (it.hasNext())
- // System.out.println(it.next(q));
- System.out.println("test");
- //serialization
- }
- catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement