Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    doubt in serialization

    hi,

    i have this code

    the code save, but don't load

    what can a do for this code work


    Code:
    public class Lista<T> extends Hashtable<String,T> implements Serializable {
    public void add(T t, String s){
        this.put(s, t); 
    }
    public String list(){
               Iterator<String> itQtds = this.keySet().iterator();
               Iterator<T> it = this.values().iterator(); 
                String str = "";
                while(it.hasNext()){
                 str += it.next() + "\n";
        }
                return str;
           }
    public void load_bin(String nome){
        try {
                FileInputStream fileIn = new FileInputStream(nome+".dat");
                ObjectInputStream in = new ObjectInputStream(fileIn);
                         in.readObject();
                in.close();
                fileIn.close();
                
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch(FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    public void save_bin(String nome){
        try {
                FileOutputStream fileOut = new FileOutputStream(nome+".dat");
                ObjectOutputStream out = new ObjectOutputStream(fileOut);
                out.writeObject(this);
                out.close();
                fileOut.close(); 
            } catch(FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    }

  • #2
    New Coder
    Join Date
    Aug 2009
    Location
    Cochin,India
    Posts
    39
    Thanks
    2
    Thanked 1 Time in 1 Post
    I couldnt find anything wrong in load_bin() function.
    Try

    Lista obj=(Lista) in.readObject();


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •