日期:2014-05-17 浏览次数:20849 次
public String addUser() {
// 取得服务器上上传文件存放的路径
String str = ServletActionContext.getServletContext().getRealPath(
"/files/");
// 获得上传文件的完整路径
String FilePath = str + File.separator + fileFileName;
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(file);
os = new FileOutputStream(FilePath);
byte[] b = new byte[1024];
int len = 0;
while ((len = is.read(b)) != -1) {
os.write(b, 0, len);
os.flush();
}
is.close();
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ss.addObject(user);
return "ha";
}
------解决方案--------------------
其实很简单的
action中申明一个文件对象
然后其他操作文件方式和平时操作文件方式相同即可