代码如下
private String myFileFileName;
private static int BUFFER_SIZe=16*1024;
private String myFileContentType;
private String imageFileName;
private String caption;
private File myFile; private static void copy(File src ,File dst){
InputStream in=null;
OutputStream out=null;
try{
in = new BufferedInputStream(new FileInputStream(src),BUFFER_SIZe);
out= new BufferedOutputStream(new FileOutputStream(dst),BUFFER_SIZe);
byte [] buffer = new byte [BUFFER_SIZe];
while (in.read()>0){
out.write(buffer);
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
if(null!=in){
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(null!=out){
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
private static String getExtention (String fileName){
int pos = fileName.lastIndexOf(".");
return fileName.substring(pos);
}
public String execute(){
imageFileName= new Date().getTime()+getExtention(myFileFileName);
System.out.println(imageFileName);
File imageFile = new File(ServletActionContext.getServletContext().getRealPath("/UploadImages")+"/"+myFileFileName);
System.out.println(imageFile);
copy(myFile,imageFile);
return SUCCESS;
}程序运行后 没什么错误 就是上传图片 图片文件损坏 打不开了 这个是什么问题造成的呢 知道的麻烦说下 谢谢
private String myFileFileName;
private static int BUFFER_SIZe=16*1024;
private String myFileContentType;
private String imageFileName;
private String caption;
private File myFile; private static void copy(File src ,File dst){
InputStream in=null;
OutputStream out=null;
try{
in = new BufferedInputStream(new FileInputStream(src),BUFFER_SIZe);
out= new BufferedOutputStream(new FileOutputStream(dst),BUFFER_SIZe);
byte [] buffer = new byte [BUFFER_SIZe];
while (in.read()>0){
out.write(buffer);
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
if(null!=in){
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(null!=out){
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
private static String getExtention (String fileName){
int pos = fileName.lastIndexOf(".");
return fileName.substring(pos);
}
public String execute(){
imageFileName= new Date().getTime()+getExtention(myFileFileName);
System.out.println(imageFileName);
File imageFile = new File(ServletActionContext.getServletContext().getRealPath("/UploadImages")+"/"+myFileFileName);
System.out.println(imageFile);
copy(myFile,imageFile);
return SUCCESS;
}程序运行后 没什么错误 就是上传图片 图片文件损坏 打不开了 这个是什么问题造成的呢 知道的麻烦说下 谢谢
解决方案 »
- 求论坛源码!仙人谁有给我发个!
- 用CSS能控制struts标签控件和控件里的文字的大小吗???
- 关于ajax返回值的问题,请各位高手指点
- 初学spring,希望大家给点意见,我的applicationcontext.xml如下
- 既然一个类的构造方法设为private,那它的构造方法有什么用呢????
- JSP中怎么得到客户端的IP和机器名字?
- 为什么别人都不做全屏网站
- 在tomcat的server.xml里面能不能设置一个域名?
- 关于中文文件的下载问题......
- 结帖通知:明天开始 会陆续强制结贴(对象:1个月以前未结的帖子大家可以在这里帖一下)!
- 历时5个月的开发:我的web erp今天开始公开测试,共19个模块160多只程序,erp中融合并实现了各种已知或未知的所有互联网上的主流技术!
- 求救!我在写一个jquery+servlet的登陆验证试验。
http://www.duduwolf.com/wiki/2007/334.html
http://shirlly.javaeye.com/blog/220895
图片上传后 程序没错误 图片也顺利上传了 就是图片文件已损坏 打不开了