Please tell me if I can use BitSet this way ;

Please set me right if I'm asking this question in the wrong forum. I am trying to write an object that contains values in a BitSet into a file using ObjectOutputStream. I loose the values upon reading the object back from the file using ObjectInputStream. What am I doing wrong? Am I way off even trying to do this?
thanks

Yes you can use it that way... maybe you could post your code as there may be another problem. The following code produces the correct result:
  public static void main( String[] args ) throws Exception {
    File f = new File( "c:/bitset" );
    ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream( f ) );
    BitSet set = new BitSet(3);
    set.set(0);
    set.set(2);
    System.out.println( set );
    out.writeObject(set);
    out.close();
    ObjectInputStream in = new ObjectInputStream( new FileInputStream(f) );
    BitSet set2 = (BitSet)in.readObject();
    System.out.println( set2 );
    in.close();
  }

Similar Messages

Maybe you are looking for