import org.apache.struts.upload.FormFile;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;
/*
* 文件上传类!
*/
public class Upload {
/**
* @param path 要存储的路径
* @param file 文件
* @return
*/
public boolean up(String path, FormFile file)throws Exception {
InputStream in = null;
OutputStream out = null;
try {
in = file.getInputStream();
out = new FileOutputStream(path);
int read = 0;
byte[] buffer = new byte[8192];
while ((read = in.read(buffer, 0, 8192)) != -1) {
out.write(buffer, 0, read);
}
out.close();
in.close();
return true;
} catch (Exception e) {
file.destroy();
e.printStackTrace();
return false;
}
}
}
(阅读次数:)