PDA

Click to See Complete Forum and Search --> : Reading data from file


US101
Jul 30th, 2001, 05:37 AM
I am trying to read a certain ammount of bytes from a file and write it to anouther file. The certain amount of bytes in not always the same. Here the number of bytes is stored in NewSize which is a long. The name of the new file is in Name, string. An error occurs saying '.class' is expected and point to buffer[] on this line:

c = in.read(buffer[], y, (int) NewSize - 1);

It seems to think buffer[] is a class??

Also the compiler does not like anything to do with the out, out.close() expects an extra ')' at the end, the out.write(buffer[].length); causes a 'cannot resolve symbol?

--------
int x, c;
int y = 0;
byte buffer[];

//All this is in a try/catch

InputStream in = new FileInputStream(FilePath);
c = in.read(buffer[], y, (int) NewSize - 1);
if (c != -1) {
OutputStream out = new FileOutputStream(Name);
out.write(buffer[].length);
out.close();
}

Dillinger4
Aug 8th, 2001, 05:53 PM
Any Luck?

US101
Aug 10th, 2001, 12:18 AM
Yes thank you, your stream copier helped, and also I found that when you create a byte array, byte buffer[], you also have to say what size of you want the array, byte buffer[] = new byte[10];

then in the rest of the code you just refer to buffer, not buffer[].

Dillinger4
Aug 10th, 2001, 07:33 AM
Cool. I was just curious to see if it worked..... :)