zoukankan      html  css  js  c++  java
  • JAVA将Byte数组转换成文件

     /**
         * 将Byte数组转换成文件
         * @param bytes byte数组
         * @param filePath 文件路径
         * @param fileName  文件名
         */
        public static void fileToBytes(byte[] bytes, String filePath, String fileName) {
            BufferedOutputStream bos = null;
            FileOutputStream fos = null;
            File file = null;
            try {
    
                file = new File(filePath + fileName);
                if (!file.getParentFile().exists()){
                    //文件夹不存在 生成
                    file.getParentFile().mkdirs();
                }
                fos = new FileOutputStream(file);
                bos = new BufferedOutputStream(fos);
                bos.write(bytes);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (bos != null) {
                    try {
                        bos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    -----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------ (蓝奏云官网有些地址失效了,需要把请求地址lanzous改成lanzoux才可以)
  • 相关阅读:
    vue proxy代理理解
    css样式鲜为人知的属性
    vue中实现元素选中互斥
    站长统计加载慢解决方法
    微信图片预览接口
    移动端兼容问题
    请求头和响应头
    清除缓存方法
    屏幕适配及rem
    清除多个定时器
  • 原文地址:https://www.cnblogs.com/pxblog/p/14919094.html
Copyright © 2011-2022 走看看