java 文件上传到读取文件内容的实例
作者:飘在北季的校园- 发布时间:2023-11-09 22:00:27
标签: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;
}
来源:https://blog.csdn.net/huoxingren0523/article/details/72366874
0
投稿
猜你喜欢
- JOL简介JOL的全称是Java Object Layout。是一个用来分析JVM中Object布局的小工具。包括Object在内存中的占用
- 这篇文章主要介绍了Java继承方法重写实现原理及解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友
- 写在前面元旦三天在家闲着无事,就看了看Linq的相关内容,也准备系统的学习一下,作为学习Linq的前奏,还是先得说说Lambda与匿名方法的
- 在很多项目中,为了安全安全考虑,需要对数据包进行加密处理,本文实例所述的即为C#加密代码,在应用开发中有很大的实用价值。说起数据包加密,其实
- 很多小伙伴刚刚接触.net这一平台,可能不清楚如何安装最新版本VS 来搭建一个好用的编译器;本文将引导大家安装VS2019 C#语言的安装第
- 本文参考借鉴:https://www.jb51.net/article/102983.htm先上效果图:自定义控件:AttendancePr
- eclipse导入appcompat项目报错解决办法我们在eclipse导入开源项目后,经常会发现找不到类似Theme.AppCompat.
- 一个是通过W、A、S、D来移动人物(示例一),另个是按屏幕上的按钮来移动人物(示例二)。很简单,只改了几行代码。下面是“Assets”文件夹
- 本文主要内容:•1、什么是Cookie•2、Cookie带来的好处•3、Cookie的主要方法 一、什么是Cookiecookie
- Flyway是一款开源的数据库版本管理工具,它更倾向于规约优于配置的方式。第一步:pom.xml添加maven依赖<!-- https
- 将网络资源url转化为File文件将互联网上的http开头的url资源,保存到本地。 private File getNetUrlHttp(
- 网络爬虫在信息检索与处理中有很大的作用,是收集网络信息的重要工具。接下来就介绍一下爬虫的简单实现。爬虫的工作流程如下爬虫自指定的URL地址开
- Android仿通话来电界面,供大家参考,具体内容如下简介:开发中需要模拟来电时的通话界面,仿照来电界面实现来电时播放铃声,界面通过动画模拟
- 本文实例讲述了Android编程实现Listview点击展开和隐藏的方法。分享给大家供大家参考,具体如下:代码较多,所以找关键点大家贴出来,
- 本文实例为大家分享了unity实现翻页按钮功能的具体代码,供大家参考,具体内容如下效果图:UI子父级关系:代码中也都有加入注释,有不懂可私信
- Spring容器中的Bean是否线程安全,容器本身并没有提供Bean的线程安全策略,因此可以说Spring容器中的Bean本身不具备线程安全
- 在用maven打包时,出现过如下两个错误:错误1:程序包javax.servlet不存在,程序包javax.servlet.http不存在错
- Servlet:当然,在servlet中,一般跳转都发生在doGet, doPost等方法里面。1) redirect 方式response
- 一、Stream类概述在.NET Framework中,文件和流是有区别的。文件是存储在磁盘上的数据集,它具有名称和相应的路径。当打开一个文
- mybatis获取表中某一列的最大值这个问题这两天也是找了好久才找到解决办法,在此记录一下。获取表中数据某一列的最大值,在mapper.xm