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
相关文档:
最近公司碰到需要用图表的形式显示一些数据,我就开始到网上查询,查到了jfreechart和amcharts,这两者我都实现过了,jfreechart最后生成图片,但是图片效果不是我想要的,然后又研究amcharts 它的效果确实很好,而且官方网站上还有好些例子可供下载,网址是:www.amcharts.com
(想要完成一个amcharts图形需要swfobjects. ......
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 ......
在Java中有时会遇见乱码的情况,这里提供了几种转换方法
(一)Java中的编码转换
(二)可以在web.xml文件中配置的自己写的过滤器
第一种方法最简单也最方便,但是只能用在少量的地方或是偶尔一两次转码,如果大面积使用就不方便了,也大大增加了编码量,如果你的项目里没有用Spring的框架开 ......