Java中的关闭图像生成器
我正在执行的步骤Java中的关闭图像生成器,java,html,jsf,Java,Html,Jsf,我正在执行的步骤 我正在从html(xhtml)创建一个图像 在JSF页面上显示图像 删除(生成的)图像和html(xhtml)->问题就出在这里 步骤1的代码: private void generateImageFromHtml(String imageName) { try { String cardPath = Constants.MEMBERSHIP_TEMPLATE_CARD_DIR; // This is path to html and
private void generateImageFromHtml(String imageName) {
try {
String cardPath = Constants.MEMBERSHIP_TEMPLATE_CARD_DIR;
// This is path to html and image
File file = new File(cardPath + imageName + ".xhtml");
int width = 600;
int height = 380;
Java2DRenderer renderer = new Java2DRenderer(file, width, height);
BufferedImage img = renderer.getImage();
FSImageWriter imageWriter = new FSImageWriter();
imageWriter.write(img, (cardPath + imageName + ".png"));
img.flush();
} catch (IOException exception) {}
}
<img src="#{facesContext.externalContext.requestContextPath}/assets/images/cards/#{myBean.cardName}.png" />
public void deleteMembershipCard() {
// Here are above code to popupate html and image paths
File card = new File(imagePath);
File xhtml = new File(xhtmlPath);
try {
card.delete(); // Not DONE Successfully
xhtml.delete(); // DONE Successfully
} catch(SecurityException se) {}
}
步骤2的代码:
private void generateImageFromHtml(String imageName) {
try {
String cardPath = Constants.MEMBERSHIP_TEMPLATE_CARD_DIR;
// This is path to html and image
File file = new File(cardPath + imageName + ".xhtml");
int width = 600;
int height = 380;
Java2DRenderer renderer = new Java2DRenderer(file, width, height);
BufferedImage img = renderer.getImage();
FSImageWriter imageWriter = new FSImageWriter();
imageWriter.write(img, (cardPath + imageName + ".png"));
img.flush();
} catch (IOException exception) {}
}
<img src="#{facesContext.externalContext.requestContextPath}/assets/images/cards/#{myBean.cardName}.png" />
public void deleteMembershipCard() {
// Here are above code to popupate html and image paths
File card = new File(imagePath);
File xhtml = new File(xhtmlPath);
try {
card.delete(); // Not DONE Successfully
xhtml.delete(); // DONE Successfully
} catch(SecurityException se) {}
}
问题:我无法删除图像,但html文件已成功删除。当我试图手动删除图像时,它会给我一条错误消息说“无法删除它,它是用Java(TM)打开的”
不知道图像在Java中打开的位置。@Karthigeyan我想知道图像在哪里(Java代码中)打开。我不想手动删除它。