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
相关文档:
有时候,类的同一种功能有多种实现方式,到底采用那种实现方式,取决于调用者
给定的参数。例如杂技师能训练动物,对于不同的动物有不同的训练方式。
public void train
(Dog dog){
//
训练小狗站立,排队,做算 ......
public void sort(int[] array) {
for(int i=0; i<array.length; i++) {
boolean flag = true;
for(int j=0; j<array.length-i-1; j++) {
if(array[j]>array[j+1]) {
int tmp = ar ......
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 ......
XJad2.2(Java源代码反编译工具)
立即下载
XJad是基于Jad核心的Java源程序反编译软件,内置Jad1.5.8e2。
XJad可处理多个*.class文件,可以处理文件夹内的所有文件,甚至可以处理*.jar文件。
XJad带有多页面文本编辑器,反编译完成后可以直接编辑查看,编辑器支持java语法的高亮显示功能。
......
InputStream stream;
Properties prop = new Properties();// 属性集合对象
stream = getClass().getResourceAsStream("NcJdbc.properties");
prop.load(stream);
stream.close();// 关闭流
String databaseName=prop.getProperty("jdbc.databaseName");
InputStream stream;
Properties prop = new Properties(); ......