- 论坛徽章:
- 0
|
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;
}
}
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/29346/showart_317486.html |
|