import java.io.*;public classByteArrayStream {public static voidmain(String[] args) {byte[] datas = fileToByteArray("D:/test/1111.mp4");
byteArrayToFile(datas,"D:/test/byteArrayNew.mp4");
}public static byte[] fileToByteArray(String filePath) {
File src= newFile(filePath);byte[] dest = null;
ByteArrayOutputStream baos= null;
InputStream is= null;try{
is= newFileInputStream(src);
baos= newByteArrayOutputStream();byte[] buf = new byte[1024 * 10];int len = -1;while ((len = is.read(buf)) != -1) {
baos.write(buf,0, len);
}
baos.flush();returnbaos.toByteArray();
}catch(FileNotFoundException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}finally{if (is != null) {try{
is.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}return null;
}public static void byteArrayToFile(byte[] src, String filePath) {
File dest= newFile(filePath);
InputStream is= null;
OutputStream os= null;try{
is= newByteArrayInputStream(src);
os= newFileOutputStream(dest);byte[] buf = new byte[1024];int len = -1;while((len = is.read(buf))!=-1){
os.write(buf,0,len);
}
os.flush();
}catch(FileNotFoundException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}finally{if (os != null) {try{
os.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}
}
}