Java 二进制格式文件转换为doc文件并保存在指定路径下
2014-12-25 16:47
483 查看
/**
* 文件下载
*
* @param request
* @param response
* @param id
* @throws Exception
* @throws NumberFormatException
*/
private void downLoadFile(HttpServletRequest request, String id)
throws NumberFormatException, Exception {
Contracttemplate ct = contracttemplateService
.queryContracttemplateById(Integer.parseInt(id));
if (ct != null) {
byte[] blobSource = ct.getBlobSource();
ByteArrayInputStream bais = new ByteArrayInputStream(blobSource);
String uploadDir = request.getSession().getServletContext()
.getRealPath("/")
+ "\\WEB-INF\\static\\contract\\";
File fileDir = new File(uploadDir);
if (!fileDir.exists()) {
fileDir.mkdirs(); //创建目录
}
String uploadDirPath = request.getSession().getServletContext()
.getRealPath("/")
+ "\\WEB-INF\\static\\contract\\" + "contracttemplate.doc";
File file = new File(uploadDirPath);
if (!file.exists()) {
file.createNewFile(); //创建文件
}
FileOutputStream outputStream = new FileOutputStream(file);
int size = 0;
while ((size = bais.read(blobSource)) != -1) {
outputStream.write(blobSource, 0, size);
}
if (outputStream != null) {
outputStream.close();
}
}
}
* 文件下载
*
* @param request
* @param response
* @param id
* @throws Exception
* @throws NumberFormatException
*/
private void downLoadFile(HttpServletRequest request, String id)
throws NumberFormatException, Exception {
Contracttemplate ct = contracttemplateService
.queryContracttemplateById(Integer.parseInt(id));
if (ct != null) {
byte[] blobSource = ct.getBlobSource();
ByteArrayInputStream bais = new ByteArrayInputStream(blobSource);
String uploadDir = request.getSession().getServletContext()
.getRealPath("/")
+ "\\WEB-INF\\static\\contract\\";
File fileDir = new File(uploadDir);
if (!fileDir.exists()) {
fileDir.mkdirs(); //创建目录
}
String uploadDirPath = request.getSession().getServletContext()
.getRealPath("/")
+ "\\WEB-INF\\static\\contract\\" + "contracttemplate.doc";
File file = new File(uploadDirPath);
if (!file.exists()) {
file.createNewFile(); //创建文件
}
FileOutputStream outputStream = new FileOutputStream(file);
int size = 0;
while ((size = bais.read(blobSource)) != -1) {
outputStream.write(blobSource, 0, size);
}
if (outputStream != null) {
outputStream.close();
}
}
}
相关文章推荐
- 如何用JAVA将二进制文件转换成BASE64格式保存到MySQL的Blob字段里并读出下载
- 转:员工信息管理 数据以二进制的格式重新保存到:指定路径中;
- java使用poi把从数据库中取出的数据写入到excel文件中并保存到指定文件路径
- 员工信息管理 数据以二进制的格式重新保存到:指定路径中;
- Java 把指定路径的文件读入内存并用字节数组保存工具方法
- Java实现获取指定路径下的指定格式的文件;
- JAVA---实现获取指定路径下的指定格式的文件;
- python某一目录下指定格式的文件路径保存到指定格式的文件中
- Java实现获取指定路径下的指定格式的文件,如bcp,txt等
- JPG,PNG等格式的图片转换的ICON保存为ICO文件
- 用java程序调用ffmpeg执行视频文件格式转换flv
- 用java程序调用ffmpeg执行视频文件格式转换flv
- Source Insight使用备忘(查看完整路径和加入指定格式文件)
- Java将Unix时间戳转换成指定格式日期
- 基于java的图片文件格式转换和线性缩放
- java文件读写操作指定编码格式[转]
- 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
- excel转换成指定格式的文件
- 文件的长路径如何转换为短路径(dos格式) 转自csdn
- 基于java的图片文件格式转换和线性缩放