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
相关文档:
2008 年 6 月 24 日
原文地址: http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0806wangys/
本文介绍 IBM FileNet P8 4.0 Platform 提供的 Content Java API。首先对 FileNet P8 Content Engine 和 API 进行概要介绍, 并说明了一些基本概念,随后详细介绍了 FileNet Content Engine提供的基于 EJB ......
有时候,类的同一种功能有多种实现方式,到底采用那种实现方式,取决于调用者
给定的参数。例如杂技师能训练动物,对于不同的动物有不同的训练方式。
public void train
(Dog dog){
//
训练小狗站立,排队,做算 ......
java 的去掉空格空行的例子:
String so = "haolong, hei eip, "
+"ting, " +
& ......
java(Web)中相对路径,绝对路径问题总结
前言:
前一段时间,由于在处理Web应用下的文件创建与移动等,因此涉及到很多关于java
中相对路径,绝对路径等问题。同时,对于Web应用中的相对路径,绝对路径,以及Java.io.File
类学习了一下。也找了一些资料。希望大家遇到类似的问题,可以更有效的解决。
========= ......
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(); ......