Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think your code could use <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html#getResourceAsStream%28java.lang.String%29" rel="nofollow">Class.getResourceAsStream()</a> instead (<code>/resources/log.ascii</code> needs to be packaged in the jar, or somewhere else on the classpath).</p> <pre><code>private static String retrieveSelectedWorkspace() throws FileNotFoundException { InputStream in = Gui.class.getResourceAsStream("/resources/log.ascii"); Scanner scanner = new Scanner(in); while(scanner.hasNextLine()) return scanner.nextLine().toString(); return null; } </code></pre> <p>But as to your actual question, you can definitely grab a folder resource from a jar, as long as that folder is packed inside the jar.</p> <p>Test.java:</p> <pre><code>class Test { public static void main(String[] args) { System.out.println(Test.class.getResource("/text.txt")); System.out.println(Test.class.getResource("/folder")); } } </code></pre> <p>Command line. Create a file and a folder. Then try both running the code from a <code>.class</code> file and running the code from a <code>.jar</code> file.</p> <pre><code>C:\Temp&gt;echo text &gt; text.txt C:\Temp&gt;md folder C:\Temp&gt;javac Test.java C:\Temp&gt;java Test file:/C:/Temp/text.txt file:/C:/Temp/folder </code></pre> <p>Create the jar:</p> <pre><code>C:\Temp&gt;jar cvf test.jar Test.class text.txt folder added manifest adding: Test.class(in = 530) (out= 347)(deflated 34%) adding: text.txt(in = 7) (out= 9)(deflated -28%) adding: folder/(in = 0) (out= 0)(stored 0%) </code></pre> <p>Run from the jar:</p> <pre><code>C:\Temp&gt;java -classpath test.jar Test jar:file:/C:/Temp/test.jar!/text.txt jar:file:/C:/Temp/test.jar!/folder </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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