/** * 根據byte數組,生成文件 * filePath 文件路徑 * fileName 文件名稱(需要帶后綴,如*.jpg、*.java、*.xml) */ public static void createFile(byte[] qrData, String filePath,String fileName) { OutputStream os = null; try { File dir = new File(filePath); if(!dir.exists()&&dir.isDirectory()){//判斷文件目錄是否存在 dir.mkdirs(); } os = new FileOutputStream(filePath+fileName); os.write(qrData, 0, qrData.length); os.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (os != null) { try { os.close(); } catch (IOException e1) { e1.printStackTrace(); } } } }
