根据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();
                }
            }
        }
    }
原文地址:https://www.cnblogs.com/shihaiming/p/11338087.html