Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to setPage() a JEditorPane with a localfile which is outside of the .jar file?
    text
    copied!<p>My program has the following path in the .jar file<br> <code>src/test/Program.class</code></p> <p>and my program is as follow...</p> <p><code>Program.java</code></p> <pre><code>package test; import java.io.File; import java.io.IOException; import javax.swing.JEditorPane; import javax.swing.JFrame; public class Program { JEditorPane editorPane; public Program() { File file = new File("temp.htm"); try { file.createNewFile(); editorPane = new JEditorPane(); editorPane.setPage(Program.class.getResource("temp.htm")); } catch (IOException e) { e.printStackTrace(); } } public JEditorPane getEditorPane(){ return editorPane; } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setVisible(true); Program p = new Program(); frame.getContentPane().add(p.getEditorPane()); } } </code></pre> <p>The problem is that I have compiled the program in a <code>.jar</code> file.<br> The <code>file.createNewFile();</code> creates the <code>temp.htm</code> file outside the <code>.jar</code> file<br> So when <code>editorPane.setPage(Program.class.getResource("temp.htm"));</code> is called the file is not found as it searches for file inside the <code>test</code> package.<br> How to <code>setPage()</code> the <code>temp.htm</code> file whiich is outside the <code>.jar</code> file but in the same folder as the <code>.jar</code> file?<br> As the <code>temp.htm</code> is a localfile and I want a relative path instead of an absolute path. </p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload