前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >文件下载,带转码->pdf->swf

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

作者头像
全栈程序员站长
发布2022-07-10 10:30:16
1.1K0
发布2022-07-10 10:30:16
举报

大家好,又见面了,我是全栈君。

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

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

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/115691.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年1月3,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档