× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Java access files in jar causes java.nio.file.FileSystemNotFoundException

Francis Galiegue
Mar 01, 2015
<p>A <code>FileSystemNotFoundException</code> means the file system cannot be created automatically; and you have not created it here.</p> <p>Given your URI, what you should do is split against the <code>!</code>, open the filesystem using the part before it and then get the path from the part after the <code>!</code>:</p> <pre><code>final Map&lt;String, String&gt; env = new HashMap&lt;&gt;(); final String[] array = uri.toString().split("!"); final FileSystem fs = FileSystems.newFileSystem(URI.create(array[0]), env); final Path path = fs.getPath(array[1]); </code></pre> <p>Note that you should <code>.close()</code> your <code>FileSystem</code> once you're done with it.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/22605666/Java%20access%20files%20in%20jar%20causes%20java.nio.file.FileSystemNotFoundException/22605905">Stack Overflow</a>.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus