java文件上传方法
文件上传方法(一次上传一个文件,多个文件的话,请写循环调用)
Upload.uploadFile(theFile, filePath)
说明:
theFile:类型是FormFile
filePath:action中路径获取方法 this.getServlet().getServletContext().getRealPath("/")
调用此方法返回文件上传后的路径名
上传多个文件时,请设置每个文件之间1秒的延迟,否则文件会被覆盖
package common.com;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.struts.upload.FormFile;
/**
* @author lsc
* 文件上传
*/
public class Upload {
/**
* 文件上传
* @param theFile(FormFile)
* @param filePath(action中路径获取方法:this.getServlet().getServletContext().getRealPath("/") )
* @return
*/
public static String uploadFile(FormFile theFile , String filePath) {
String fileName = theFile.getFileName();//取得上传的Msds文件名
try{
String hardPath = "";
/*
* 取当前系统路径D:\Tomcat5\webapps\coka\ 其中coka 为当前context
*/
//String filePath = this.getServlet().getServletContext().getRealPath("/");
File savePath = new File(filePath + "UploadFiles\\");
if (!savePath.exists()) {
savePath.mkdir();
}
if
相关文档:
1、语法:必须比较熟悉,在写代码的时候IDE的编辑器对某一行报错应该能够根据报错信息知道是什么样的语法错误并且知道任何修正。
2、命令:必须熟悉JDK带的一些常用命令及其常用选项,命令至少需要熟悉:appletviewer、 HtmlConverter、jar、 java、javac、javadoc、javap、javaw、native2ascii、serialver,如果这些命令 ......
StringBuilder path = new StringBuilder(request.getScheme());
path.append("://").append(request.getServerName());
path.append(":").append(request.getServerPort()).append(request.getContextPath());
System.out.println("***********path:" + path);
Syste ......
JXL.JAR 操作Excel文件开源包
这里简单讲些项目中用到的一些方法!(项目的环境是Struts2 hibernate3 resin3 )
// Excel文件存放路径
String path = ServletActionContext.getServletContext().getRealPath("")+"userfiles\\train_excel\\text.xls";
// 生成Excel文件
WritableWorkbook wwb = Workbook.creat ......
java线程池技术浅析
为什么要用线程池?
诸如Web服务器、数据库服务器、文件服务器或邮件服务器之类的许多服务器应用程序都有面向处理来自某些远程来源的大量短小的任务。请求以某种方式到达服务器,这种方式可能是通过网络协议(例如HTTP、FTP或POP)、通过JMS队列或者可能通过轮询数据库。不管请求如何达到,服务器应用程 ......