0

I have created a file called"output.txt" using this code snippet.

public static void main(String args[]) throws IOException{
    BitSet bitset = new BitSet();
    for(int i = 0; i<100; i++){
        if(i%2 == 0){
            bitset.set(i, false);
        }else{
            bitset.set(i, true);
        }
    }

    FileOutputStream fout = new FileOutputStream("output.txt");
    byte[] bs = bitset.toByteArray();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(bs);
    baos.writeTo(fout);
}

Now how do I read "output.txt" file and get my byte[] bs back? Can anyone give me code for that? I am having trouble writing ByteArrayInputStream code.

Thanks

2
  • ByteArrayInputStream is an in-memory stream to read from a byte array, you must use FileInputStream to read byte array from file Commented Apr 23, 2016 at 10:00
  • On the other hand, I have another question. How do I read the bits from my output.txt file instead of a byte? Commented Apr 23, 2016 at 10:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.