I'm trying to insert an image into a HTML file from a java method with Eclipse. When I export the project into a Runnable jar, the image doesn't appear.
I searched a lot on the internet, and i did a ressource folder, but it doesn't work.
src
--test4
----IHM2.java
----test4.java
--res
----logo2.png
public class IHM2
{
private File htmlFile;
private FileWriter fw;
private BufferedWriter writer;
public IHM2() throws IOException {
htmlFile = new File("IHM2.html");
fw = new FileWriter("IHM2.html");
writer = new BufferedWriter(fw);
}
public void HTML_opening() throws IOException
{
writer.write("<html>");
writer.write("<head>");
writer.write("</head>");
writer.write("<body>");
writer.write(" <img src='res/logo2.png'>");
}
public void HTML_closing() throws IOException
{
writer.write("</body>");
writer.write("</html>");
writer.close();
Desktop.getDesktop().browse(htmlFile.toURI());
}
}
Any one please provide me an answer ?
SOLUTION :
I put writer.write(" <img src='./logo2.png'>");
Because I looked into the .jar file and logo2.png was out of the folder test4.