zoukankan      html  css  js  c++  java
  • 常用文件转换公共方法

    /**
    * 文件转pdf字节数组
    * @param file
    * @return
    * @throws IOException
    */
    private static byte[] transform(File file) throws IOException {
    String name = file.getName().toLowerCase();
    if (name.endsWith(".pdf")) {
    return FileUtils.readFileToByteArray(file);
    } else if (name.endsWith(".xls")) {
    byte[] excelData = FileUtils.readFileToByteArray(file);
    return FileTranslateTools.getInstance().excelToPdf(excelData, false);
    } else if (name.endsWith(".doc")) {
    WordToPdfUtils utils = new WordToPdfUtils();
    return utils.wordToPdf(FileUtils.openInputStream(file));
    } else {
    throw new AppException(file.getName() + "文件类型不正确,必须上传 pdf、xls、doc中的一种。");
    }
    }

    /**
    * 将字节写入pdf临时文件
    *
    * @param other1Byte
    * @return
    * @throws IOException
    */
    private static File tFile(byte[] other1Byte) throws IOException {
    String dir = System.getProperty("java.io.tmpdir");
    File f = new File(FilenameUtils.concat(dir, System.currentTimeMillis() + ".pdf"));//默认的临时文件路径
    FileUtils.writeByteArrayToFile(f, other1Byte);
    return f;
    }

  • 相关阅读:
    IIS7最大上传附件大小配置
    数据表的identity
    服务器×××上的MSDTC不可用解决办法——Orchard(转)
    IOS项目中使用全局变量
    九宫格解锁的实现
    UINavigationControlle类详解
    jar仓库
    django安装
    django入门
    值得阅读的pyhon文章
  • 原文地址:https://www.cnblogs.com/tiansan/p/7346049.html
Copyright © 2011-2022 走看看