根据byte[]数组,生成相对应的文件并保存指定路径下

2020-02-02 15:39:26

我在做视频ts解密的时候,用到了InputStream流转byte[],解密byte[],解密后的byte[],再通过new ByteArrayInputStream(byt)转回到inputStream,再进行文件保存。

搞了一天一页啊,大文件,直接内存溢出,各种全局变量,各种软饮用,各种置空,都无济于事,最后我猜测是ByteArrayInputStream不能够释放引起的,无论怎么做都不行,几近崩溃。

最后想到了办法,逐个击破ts,直接用byte[]数组保存为文件,越过那些乱七八糟的。

果真,成啦。我的天啊。


根据byte[]数组,生成相对应的文件并保存指定路径下。

      /**
     * bfile 需要转换成文件的byte数组
     * filePath  生成的文件保存路径
     * fileName  生成文件后保存的名称如test.pdf,test.jpg等
     */
    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);
            boolean isDir = dir.isDirectory();
    		if (!isDir) {// 目录不存在则先建目录
    			try {
    				dir.mkdirs();
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
            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();
                }
            }
        }
    }


  • 2020-05-21 10:56:53

    fixed z-index失效

    作为一个假的前端,在调试一个页面时出现了如下bug。 左侧的菜单固定为fixed时,二级菜单无法设置有效的z-index,导致菜单隐藏在页面元素之下,明明页面元素的z-index是1,但是无论把菜单的z-index设置为多大,都不管用。

  • 2020-05-24 08:10:18

    echarts标题(title)配置

    show:true,//显示策略,默认值true,可选为:true(显示) | false(隐藏) text: '主标题',//主标题文本,'\n'指定换行 link:'',//主标题文本超链接,默认值true target: null,//指定窗口打开主标题超链接,支持'self' | 'blank',不指定等同为'blank'(新窗口) subtext: '副标题',//副标题文本,'\n'指定换行 sublink: '',//副标题文本超链接