程序如下:
package linkman.helper;
import java.io.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;
public class UpLoadBean {
private String SavePath = null;
private String FileName = null;
private String Sperator = null;
private String ErrMsg = "正常返回";
private byte[] bt = new byte[4096];
private byte[] prebt = new byte[4096];
private int t = -1;
private long FileSize = -1;
private boolean UserDefineFileName = false;
/////////////////////////////////////////////////
public UpLoadBean () {
FileName = bringFileName ();
}
public UpLoadBean (String savepath) {
SavePath = savepath;
FileName = bringFileName ();
}
/////////////////////////////////////////////////
// 文件名信息
private String bringFileName () {
Calendar dt = Calendar.getInstance ();
String str = "" + dt.get (Calendar.YEAR) + dt.get (Calendar.MONTH) + dt.get (Calendar.DAY_OF_MONTH);
str = str + dt.get (Calendar.HOUR) + dt.get (Calend
return str;
}
public void setFileName (String filename) {
FileName = filename;
UserDefineFileName = true;
}
public String getFileName () {
return FileName;
}
/////////////////////////////////////////////////
// 上传文件主程序
public boolean UpLoad (HttpServletRequest request) throws Exception {
if (SavePath == null) {
setErrorMessage ("未设置保存上传文件的路径");
return false;
}
request.setCharacterEncoding("utf-8");
ServletInputStream in = request.getInputStream ();
////////////////////////////////////////////
新闻热点
疑难解答