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
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
if (!file.delete())
{
file.deleteOnExit();
}
它不能被,可能是src还引用着这个资源。看看RenderedOp还有没有别的方法可以释放它所引用的文件
这样,最后该文件还是会被删除的。