java 上传附件的一点积累
1、第一种:
File inFile = new File(downfileA);//downfileA是前台传过来的,文件路径
String fileName = inFile.getName();
String path = request.getSession().getServletContext().getRealPath("/");
File outFile = new File(path);
FileUtils.copyFile(new File(fileName), outFile);
2、第二种:
InputStream is = null;
OutputStream os = null;
byte[] number = new byte[1024];
try
{
File inFile = new File(downfileA);//downfileA是前台传过来的,文件路径
String fileName = inFile.getName();
String path = request.getSession().getServletContext().getRealPath("/")+fileName;
is = new BufferedInputStream(new FileInputStream(downfileA), 1024);
os = new BufferedOutputStream(new FileOutputStream(path),1024);
while(is.read(number) > 0)
{
os.write(number);
}
os.close();
is.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
注:上述两种方法在linux下不好用。会提示找不到路径。
3、在linux下通过servlet的方式解决。(有时间再补充)
java 上传附件的一点积累的更多相关文章
- java上传附件,批量下载附件(一)
上传附件代码:借助commons-fileupload-1.2.jar package com.str; import java.io.BufferedInputStream;import java. ...
- java上传附件含有%处理或url含有%(URLDecoder: Illegal hex characters in escape (%) pattern - For input string)
在附件名称中含有%的时候,上传附件进行url编码解析的时候会出错,抛出异常: Exception in thread "main" java.lang.IllegalArgumen ...
- Easyui前端、JAVA后台 上传附件
前端使用easyui框架,后台使用JAVA 的JFinal框架开发 功能描述:实现附件上传功能.文件上传路径为:../upload(上传文件夹)/身份证号/慢病编码/上传的附件. 细节要求:实现多图片 ...
- jmeter 上传附件脚本报Non HTTP response code: java.io.FileNotFoundException
如果上传附件报如下错误,就需要把附件放到和脚本同一路径下就解决了
- jquery 通过ajax FormData 对象上传附件
之前上传附件都是用插件,或者用form表单体检(这个是很久以前的方式了),今天突发奇想,自己来实现附件上传,具体实现如下 html: <div> 流程图: <input id=& ...
- spring MVC上传附件
spring mvc为我们封装了十分简单的上传附件的方法,以下通过一个例子学习. 1.jsp <%@ page language="java" contentType=&qu ...
- jmeter笔记(4)--测试上传附件
性能测试过程中有HTTP请求上传附件的场景,记录一下运用fiddler和jmeter实现jforum发表上传附件的帖子的过程. 1.fiddler录制脚本 2.打开录制的脚本,调整信息头管理器中信息 ...
- Jmeter上传附件EXCEL
1.通过对上传附件接口进行抓包,获取的信息如下: 2.在jmeter脚本中添加http请求,并添加http请求头信息如下: 3.在http请求中添加上传附件的内容如下,由于我上传的是excel,所以M ...
- jeecms系统使用介绍——通过二次开发实现对word、pdf、txt等上传附件的全文检索
转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/76912307 本文出自[我是干勾鱼的博客] 之前在文章<基于Java的门户 ...
随机推荐
- 变量使用self.foo还是_foo
selfOR_html, body {overflow-x: initial !important;}html { font-size: 14px; } body { margin: 0px; pad ...
- Selenium (1) —— Selenium安装与测试(101 Tutorial)
Selenium (1) -- Selenium安装与测试(101 Tutorial) jvm版本: 1.8.0_65 selenium版本: v2.48.0 (Standalone Selenium ...
- 俞军的PM12条
俞军的PM12条:1.PM首先是用户2.站在用户角度看待问题3.用户体验是一个完整的过程4.追求效果,不做没用的东西5.发现需求,而不是创造需求6.决定不做什么,往往比决定做什么更重要7.用户是很难 ...
- jQuery.countdown倒计时插件
https://github.com/hilios/jQuery.countdown 文档:http://hilios.github.io/jQuery.countdown/documentation ...
- Spark的机器学习算法mlib的例子运行
Spark自带了机器学习的算法mlib,页面网址 http://spark.incubator.apache.org/docs/latest/mllib-guide.html 但是运行的时候,遇到了很 ...
- Git 环境设置(安装)
在使用Git之前,必须安装它,并做一些基本配置的变化.下面是步骤在Ubuntu和CentOS Linux安装 Git 客户端. Git客户端安装 如果使用的是GNU/ Linux 发行版Debian基 ...
- 删除json对象中空值
function deleteEmptyProperty(obj){ var object = obj; for (var i in object) { var value = object[i]; ...
- ubuntu下IDEA配置tomcat报错Warning the selected directory is not a valid tomcat home
产生这个问题的主要原因是文件夹权限问题. 可以修改文件夹权限或者更改tomcat文件目录所有者. 这里我直接变更tomcat文件夹所有者: sudo chown -R skh:skh tomcat-/ ...
- python使用pymongo访问MongoDB的基本操作,以及CSV文件导出
1. 环境. Python:3.6.1 Python IDE:pycharm 系统:win7 2. 简单示例 import pymongo # mongodb服务的地址和端口号mongo_url = ...
- Kryonet client disconnects after send a packet to server (java)
http://stackoverflow.com/questions/25934876/kryonet-client-disconnects-after-send-a-packet-to-server ...