根據byte數組,生成文件


 

 

 

/**
     * 根據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();
                }
            }
        }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM