0

I need to create a URI to a virtual filesystem (jimfs) in java. I need to do this so that I can add files to a zip archive (by defining the zipfile as a filesystem). How can I point the URI variable below to my virtual filesystem? (or, if that won't work, is there another way to do this)

filesystem = Jimfs.newFileSystem(Configuration.unix())
   URI zipDisk = zipFile.toUri()
        FileSystems.newFileSystem(zipDisk, zip_properties).withCloseable { FileSystem zipfs ->
            Path ZipFilePath = zipfs.getPath(fileToZip.getFileName().toString())                //Define the file as it will exist in the zipfile
            Files.copy(fileToZip,ZipFilePath, StandardCopyOption.REPLACE_EXISTING);
        }

This code produces a "may not have a path, query, or fragment" error.

Steve
  • 4,457
  • 12
  • 48
  • 89
  • jimfs is an in-memory virtual filesystem. I think you meant to use the zip virtual filesystem instead. This question doesn't seem to have anything to do with jimfs. – TubesHerder Feb 02 '18 at 21:50
  • What if I want to zip a file that's sitting on a virtual filesystem? – Steve Feb 08 '18 at 18:48
  • You can't get a URI from a jimfs Path. You have to use methods that take a Path object directly. Then it doesn't matter if the Path comes from the local filesystem or jimfs. – TubesHerder Feb 09 '18 at 19:52

0 Answers0