• 文件下载,带转码->pdf->swf


    private String upload = "保存的路径";


    //文件下载

    public String download() {
    //初始化
    this.initContext();
    String apath = request.getSession().getServletContext().getRealPath(upload);

    File af = new File(apath);
    // 假设没有这个目录。就创建个目录
    if (!af.exists()) {
    af.mkdirs();
    }


    String filenewaddress = request.getSession().getServletContext().getRealPath(upload);
        
    System.out.println("開始下载,请稍后……");
    URL urlfile = null;
    HttpURLConnection httpUrl = null;
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;
    try {

    // 把下载地址赋给urlfile 
    urlfile = new URL(fileoldaddress);
    // 打开下载 URL 引用的资源的通信链接(假设尚未建立这种连接)
    httpUrl = (HttpURLConnection) urlfile.openConnection();
    // 建立与指定socket的连接
    httpUrl.connect();
    // 提供一个默认的文件名称
    String context = httpUrl.getHeaderField("Content-Disposition");
    // 推断context是否为空
    if (context == null) {
    // 取地址最后的/后面的字符当做名字
    filename1 = fileoldaddress.substring(fileoldaddress
    .lastIndexOf("/") + 1, fileoldaddress.length());
    filenewaddress = filenewaddress + "\" + filename1;
    } else {
    filename1 = context.substring(context.lastIndexOf("=") + 1,
    context.length());
    filenewaddress = filenewaddress + "\" + filename1;
    }
    // 把本地保存地址赋给f
    File f = new File(filenewaddress);
    bis = new BufferedInputStream(httpUrl.getInputStream());
    bos = new BufferedOutputStream(new FileOutputStream(f));
    int len = 2048;
    byte[] b = new byte[len];
    while ((len = bis.read(b)) != -1) {
    bos.write(b, 0, len);
    }
    bos.flush();
    bis.close();
    httpUrl.disconnect();
    System.out.println("下载完毕。");
    } catch (Exception e) {
    System.out.println("无效下载地址,错误信息:" + e.getMessage());
    this.msg = "下载失败!";
    this.success = false;
    } finally {
    try {
    if (bis != null)
    bis.close();
    if (bos != null)
    bos.close();
    } catch (IOException e) {
    System.out.println("系统错误,错误信息:" + e.getMessage());
    System.out.println("请联系管理员!");
    }
    }


    // 下载到本地结束

    // 取绝对路径+名
    String filepath = apath + "\" + filename1;


    System.out.println(filepath);
    // 转格式
    DocConverter d = new DocConverter(filepath);
    d.conver();
    // 转格式结束
    return "success";

    }


    转码须要用到两个软件!

        Apache_OpenOffice_incubating_3.4.1_Win_x86_install_zh-CN

                                                      swftools

    必须先启动这两个软件,才干转码

  • 相关阅读:
    (转)一篇教会你写90%的shell脚本
    (转)printf命令详解
    (转)linux shell 字符串操作详解 (长度,读取,替换,截取,连接,对比,删除,位置 )
    (转)Shell中read的选项及用法
    (转)linux中shell变量$#,$@,$0,$1,$2的含义解释/Shell中的${}、##和%%使用范例/export
    (转)linux运维人员必会的22道shell编程面试题及视频讲解
    (转)李文周的博客
    ROS报错“An error occurred during the signature verification”的解决办法
    RRT and RRT Variants
    ROS LocalPlanner 基于自行车模型的DWA
  • 原文地址:https://www.cnblogs.com/yxwkf/p/5270125.html
Copyright © 2020-2023  润新知