KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have been testing all possible variations and permutations, but I can't seem to construct a FileSystemProvider with the zip/jar scheme for a path (URI) that contains spaces. There is a very simplistic test case available at Oracle Docs . I took the liberty of modifying the example and just adding spaces to the URI, and it stops working. Snippet below: import java.util.*; import java.net.URI; import java.nio.file.*; public class Test { public static void main(String [] args) throws Throwable { Map<String, String> env = new HashMap<>(); env.put("create", "true"); URI uri = new URI("jar:file:/c:/dir%20with%20spaces/zipfstest.zip"); Path dir = Paths.get("C:\\dir with spaces"); if(Files.exists(dir) && Files.isDirectory(dir)) { try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {} } } } When I execute this code (Windows, JDK7u2, both x32 and x64), I get the following exception: java.lang.IllegalArgumentException: Illegal character in path at index 12: file:/c:/dir with spaces/zipfstest.zip at com.sun.nio.zipfs.ZipFileSystemProvider.uriToPath(ZipFileSystemProvider.java:87) at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:107) at java.nio.file.FileSystems.newFileSystem(FileSystems.java:322) at java.nio.file.FileSystems.newFileSystem(FileSystems.java:272) If I use + instead of %20 as the space escape character, a different exception is thrown: java.nio.file.NoSuchFileException: c:\dir+with+spaces\zipfstest.zip at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79) at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97) at sun.nio.fs.WindowsException.rethrow
Tags (comma-separated)
Save Edits
Cancel