1

I have two byte arrays which I have put in an array list.The Code for which is here:

ArrayList al = new ArrayList();    
FileInputStream fis=new FileInputStream(bin);
fis.read(file, 0, 2048);
metas="123456789123";
meta=metas.getBytes();
al.add(meta);
al.add(file);

But when I try to put it in an output stream like this fos.write(al.toArray());

It gives the error As

no suitable method found for write(Object[]) method FileOutputStream.write(byte[],int,int) is not applicable

what may be the problem

6
  • 1
    Sidenote: the fis.read(...) not necesarily reads all 2k data into file (I guess file is an array). It reads what it has available. You must call read repeteadely until 2k is readed, or until read returns <=0 (end of file). It's not generating the problem you have, but will be an issue later. Commented Sep 11, 2012 at 14:04
  • What exactly do you want to write in that file? Both byte arrays? Commented Sep 11, 2012 at 14:05
  • 1
    Try to use ObjectOutputStream. Commented Sep 11, 2012 at 14:06
  • Yes, One array consists of some data that will be added to every 2k of data(I know that i have to set up a loop) and the other will contain that data,both have to be written as one single unit. Commented Sep 11, 2012 at 14:08
  • Instead of adding the data to a list, you can write the bytes directly to a file. Commented Sep 11, 2012 at 14:14

1 Answer 1

2

It's not clear what you want to do. If you want to write both the byte arrays in a file use:

for(byte[] arr: al) {
    fos.write(arr);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.