真急啊

ttmissyou 2008-03-21 02:13:21
public static void main(String[] args) throws Exception{
String inputFile = "c:/a.tif";
String outputFile = "c:/a.jpg";
RenderedOp src = JAI.create("fileload", inputFile);
OutputStream os = new FileOutputStream(outputFile);
JPEGEncodeParam param = new JPEGEncodeParam();
ImageEncoder enc = ImageCodec.createImageEncoder("JPEG", os,param);
enc.encode(src);

src.dispose();
os.flush();
os.close();

File file = new File(inputFile);
if(file.exists())
System.out.println(file.delete());
}

这段代码是把tif图片转换成jpg图片 之后删除。
现在的问题是转换成功只后不能删除。原因是原图片正在使用,可能是因为流或者别的没关掉。可是我已经关闭了OS
...全文
56 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
DiligencyMan 2008-03-21
  • 打赏
  • 举报
回复
两个流都需要关闭。
DiligencyMan 2008-03-21
  • 打赏
  • 举报
回复
public static void main(String[] args) throws Exception{
String inputFile = "c:/a.tif";
String outputFile = "c:/a.jpg";
RenderedOp src = JAI.create("fileload", inputFile);
OutputStream os = new FileOutputStream(outputFile);
JPEGEncodeParam param = new JPEGEncodeParam();
ImageEncoder enc = ImageCodec.createImageEncoder("JPEG", os,param);
enc.encode(src);

src.dispose();
src.flush();
src.close();
os.flush();
os.close();

File file = new File(inputFile);
if(file.exists())
System.out.println(file.delete());
}
ChangXiangzhong 2008-03-21
  • 打赏
  • 举报
回复
c:\\a.tif
yyb0815 2008-03-21
  • 打赏
  • 举报
回复
你要删除的应该是 a.tif文件吧,这和你的OS是没有关系的,OS是a.jpg的流!
应该是src没有关闭!

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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