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

时间:2022-10-28 11:53:41

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

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

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

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

5.检验值的合法性;

6.循环保存到对象中。

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

java" id="highlighter_529809">
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 文件上传到读取文件内容的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/huoxingren0523/article/details/72366874