请教一个struts 上传的问题

cnidb 2005-02-03 09:12:52
用的是struts 上传自带例子
上传成功是没问题,
但是,上传的图片经常只有一半还不到.
也就是说图片的下面一半或者更多的部分是空白(这种情况gif格式的图片居多)

还有一种情况就是图片错位..上传后图片的上方和下文位置错开了10到15像素左右不等(这种情况jpg格式的图片居多)

诚请指教,谢谢
...全文
100 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
以梦为马 2005-02-04
  • 打赏
  • 举报
回复
啥也别说了,缘分啦~
cnidb 2005-02-03
  • 打赏
  • 举报
回复
byte[] buffer = new byte[8192];
int bytesRead = 0;
while ((bytesRead = stream.read(buffer, 0, 8192))!= -1) {
baos.write(buffer, 0, bytesRead);
}

//data = new String(baos.toByteArray());
File newFile = File(uploadPath + userID + "_" + fileName);
FileOutputStream out = new FileOutputStream(newFile);
baos.writeTo(out);
baos.flush();
out.close();
lzlng 2005-02-03
  • 打赏
  • 举报
回复
贴代码看看
laoxing521 2005-02-03
  • 打赏
  • 举报
回复
没碰到过

俺传文件时,没一点问题
cnidb 2005-02-03
  • 打赏
  • 举报
回复
谢谢kui的回复

但是用你的代码会出现以下错误呀
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1263)
at com.ChangeNet.PublicBeans.Images.createXimg(Images.java:42)
kui 2005-02-03
  • 打赏
  • 举报
回复
如果到www.javawebstudio.com提问将得到更快的回答。

试把代码改成:

FormFile file = myform.getTheFile();
InputStream stream = file.getInputStream();
String filename=getServlet().getServletContext().getRealPath("/")+file.getFileName();
OutputStream bos = new FileOutputStream(filename);
int bytesRead = 0;
byte[] buffer = new byte[8192];

while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧