/*
获得指定文件的byte数组
*/
public static byte[] getBytes(String filePath){
byte[] buffer = null;
try {<br /> File file = new File(filePath);<br /> FileInputStream fis = new FileInputStream(file);<br /> ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);<br /> byte[] b = new byte[1000];<br /> int n;<br /> while ((n = fis.read(b)) != -1) {<br /> bos.write(b, 0, n);<br /> }
fis.close();<br /> bos.close();<br /> buffer = bos.toByteArray();<br /> } catch (FileNotFoundException e) {<br /> e.printStackTrace();
} catch (IOException e) {<br /> e.printStackTrace();
}<br /> return buffer;
}
/**<br /> qzf <br /> * 根据byte数组,生成文件<br /> */<br /> public static void getFile(byte[] bfile, String filePath,String fileName) {<br /> BufferedOutputStream bos = null;<br /> FileOutputStream fos = null;<br /> File file = null;<br /> try {<br /> File dir = new File(filePath);<br /> if(!dir.exists()&&dir.isDirectory()){//判断文件目录是否存在<br /> dir.mkdirs();<br /> }
file = new File(filePath+"\\"+fileName);<br /> fos = new FileOutputStream(file);<br /> bos = new BufferedOutputStream(fos);<br /> bos.write(bfile);
} catch (Exception e) {<br /> e.printStackTrace();
} finally {<br /> if (bos != null) {<br /> try {<br /> bos.close();<br /> } catch (IOException e1) {<br /> e1.printStackTrace();<br /> }
}<br /> if (fos != null) {<br /> try {<br /> fos.close();<br /> } catch (IOException e1) {<br /> e1.printStackTrace();
}<br /> }<br /> }<br /> }