I have a File object that represents a file on the file system. I want
to use that File to obtain a an array of bytes (byte[]). Can someone
tell me how to do this?
Thanks
>I have a File object that represents a file on the file system. I want
>to use that File to obtain a an array of bytes (byte[]). Can someone
>tell me how to do this?
See http://mindprod.com/applets/fileio.html
tell it you want to read raw bytes, unbuffered from a file.
Then read the entire file into a byte array File.length() bytes long
in one fell swoop.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Viv - 08 Nov 2005 08:59 GMT
package Practice;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Temp {
public static void main(String[] args)
{
File file = new File("c:/EventItemBroker.java");
byte[] b = new byte[(int) file.length()];
try {
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(b);
for (int i = 0; i < b.length; i++) {
System.out.print((char)b[i]);
}
} catch (FileNotFoundException e) {
System.out.println("File Not Found.");
e.printStackTrace();
}
catch (IOException e1)
{
System.out.println("Error Reading The File.");
e1.printStackTrace();
}
}
}