/*
    获得指定文件的byte数组
    */
    public static byte[] getBytes(String filePath){
    byte[] buffer = null;

    1. 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 /> }
    2. fis.close();<br /> bos.close();<br /> buffer = bos.toByteArray();<br /> } catch (FileNotFoundException e) {<br /> e.printStackTrace();
    3. } catch (IOException e) {<br /> e.printStackTrace();
    4. }<br /> return buffer;
    5. }
    6. /**<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 /> }
    7. file = new File(filePath+"\\"+fileName);<br /> fos = new FileOutputStream(file);<br /> bos = new BufferedOutputStream(fos);<br /> bos.write(bfile);
    8. } catch (Exception e) {<br /> e.printStackTrace();
    9. } finally {<br /> if (bos != null) {<br /> try {<br /> bos.close();<br /> } catch (IOException e1) {<br /> e1.printStackTrace();<br /> }
    10. }<br /> if (fos != null) {<br /> try {<br /> fos.close();<br /> } catch (IOException e1) {<br /> e1.printStackTrace();
    11. }<br /> }<br /> }<br /> }