Posted By:
Almagest_FUTT
Posted On:
Monday, August 1, 2005 03:20 PM
Come on... you shouldn't even be able to compile that.
The
write method takes either an
int, to write a single
byte /
char, or a byte array, to write data.
Now, i don't know what you are trying to do, but if you really just want to write the (numeric) file length's value to your stream (which seems bogus to me, but whatever), you'll have to split your long into the eight bytes it's made up of, for instance like that:
public static byte[] longToBytes(long l, boolean msb){
byte[] ret = new byte[8];
int shift;
for(int ss = 0; ss < ret.length; ss++){
shift = 8 * (msb ? ret.length - ss - 1 : ss);
ret[ss] = (byte) ((l >>> shift) & 0xff);
}
return ret;
}
(Note: "msb" means "most significant byte first", aka nokia-network-byte-order. Test it. You'll probably need "true".)
And then: os.write(longToBytes(file1.length(), true));
Mind you that, though of course i do not know your needs, your operation seems highly bizarre.