欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

java 文件上传到读取文件内容的实例

时间:2021-06-20 08:49:28|栏目:JAVA代码|点击:

1.下载文件,将文件保存到本地。(只试用excel);

2.对文件的标题进行检验;

3.获取导入的批次(取一个表的一个值,加1);

4.循环获取文件某一个行,某一列的值,set到对象中;

5.检验值的合法性;

6.循环保存到对象中。

7.用map将错误的信息和正确的信息,JSONObject.fromObject(map);

public String uploadFile() throws Exception {
logger.info("开始导入规则文件:" + fileInputFileName);
InputStream is = new FileInputStream(fileInput);
String uploadPath = ServletActionContext.getServletContext()
.getRealPath("/upload");
System.out.println(uploadPath);
File targetFile = new File(uploadPath, this.getFileInputFileName());
OutputStream os = new FileOutputStream(targetFile);
byte[] buffer = new byte[1024];
int length = 0;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
is.close();
os.close();
Map<String, Object> map = personalKPIMonitorManualRuleService
.importRules(targetFile);
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println(JSONObject.fromObject(map));
// if(flag==true){
// logger.info("规则文件导入成功:"+fileInputFileName);
// out.println("规则文件导入成功:"+fileInputFileName);
// }else{
// logger.info("规则文件导入失败:"+fileInputFileName);
// out.println("规则文件导入失败,详见日志:"+fileInputFileName);
// }
out.flush();
out.close();
return null;
}

上一篇:java 中序列化与readResolve()方法的实例详解

栏    目:JAVA代码

下一篇:Windows系统中Java调用cmd命令及执行exe程序的方法

本文标题:java 文件上传到读取文件内容的实例

本文地址:http://www.codeinn.net/misctech/145094.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有