/**
* Gets the byte array of the specified file
*/
Private byte[] GetBytes (String filePath) {
byte[] buffer = NULL;
try {
File File = new file (FilePath);
FileInputStream fis = new FileInputStream (file);
Bytearrayoutputstream BOS = new Bytearrayoutputstream (1000);
Byte[] B = new byte[1000];
int n;
while ((n = fis.read (b))! =-1) {
Bos.write (b, 0, N);
}
Fis.close ();
Bos.close ();
Buffer = Bos.tobytearray ();
} catch (FileNotFoundException e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
return buffer;
}
/**
* Based on byte array, generate file
*/
public static void GetFile (byte[] bfile, String filepath,string fileName) {
Bufferedoutputstream BOS = NULL;
FileOutputStream fos = null;
File file = null;
try {
File dir = new file (FilePath);
if (!dir.exists () &&dir.isdirectory ()) {//Determine if the file directory exists
Dir.mkdirs ();
}
File = new file (filepath+ "\ \" +filename);
FOS = new FileOutputStream (file);
BOS = new Bufferedoutputstream (FOS);
Bos.write (bfile);
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (BOS! = NULL) {
try {
Bos.close ();
} catch (IOException E1) {
E1.printstacktrace ();
}
}
if (fos! = null) {
try {
Fos.close ();
} catch (IOException E1) {
E1.printstacktrace ();
}
}
}
}
Java files and byte array conversions