zoukankan      html  css  js  c++  java
  • Java根据byte数组,生成文件

    原文出自:https://blog.csdn.net/seesun2012

    根据byte数组,生成文件

    自己写的小案例,找个地方记录一下

    package com.seesun2012.utils;
    
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    /**
     *根据byte数组,生成文件
     *
     * @author seesun2012@163.com
     *
     */
    public class FileUtil {
    
    	/**
         * 根据byte数组,生成文件
         * filePath  文件路径
         * fileName  文件名称(需要带后缀,如*.jpg、*.java、*.xml)
         */
        public static void getFile(byte[] bfile, String filePath,String fileName) {
            BufferedOutputStream bos = null;
            FileOutputStream fos = null;
            File file = null;
            try {
                File dir = new File(filePath);
                if(!dir.exists()&&dir.isDirectory()){//判断文件目录是否存在
                    dir.mkdirs();
                }
                file = new File(filePath + File.separator + fileName);
                fos = new FileOutputStream(file);
                bos = new BufferedOutputStream(fos);
                bos.write(bfile);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (bos != null) {
                    try {
                        bos.close();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    
    }
    
    
  • 相关阅读:
    Java基本数据类型的包装类
    Java数据类型基础
    Xscan安装
    Notepad++配置HexEditor插件
    [WP]XCTF-re2-cpp-is-awesome
    [WP]XCTF-tt3441810
    [WP]XCTF-re1-100
    [WP]XCTF-Mysterious
    [WP]xctf-parallel-comparator-200
    [WP]XCTF-elrond32
  • 原文地址:https://www.cnblogs.com/seesun2012/p/9214619.html
Copyright © 2011-2022 走看看