0

What's the best way of processing *ix file path strings when running on Windows?

If I just use Paths.get() it invokes Filesystem.getDefault() which ends up processing it like a Windows path. The parsing seems to work in my tests but they're pretty rudimentary, and of course toString uses the wrong path separator.

Can I manually load up the LinuxFileSystem somehow? Or should I use the commons-io parser instead?

6
  • 1
    I believe that all Windows systems since Windows 2000 accept / as well as '\' as the file separator character, in their API's. So most likely you don't need to do anything, as long as everything on Windows will be on the same drive. If this doesn't work, please provide an example of what doesn't work and what you want to accomplish. Commented Nov 12, 2016 at 7:06
  • Like I said it does parse in my basic tests, but the output is uses the wrong path separator. I suspect the windows parser might have some issues with backslashes which are legal in *ix path names. Commented Nov 12, 2016 at 7:54
  • I doubt it, because one JDK distribution is oriented either to Unix or either to Windows. The only chance I think of is that you look for an opensource distribution of some UnixFileSystemProvider and import into your application's runtime. And even in that case, I have my doubts, because UnixFileSystemProvider deals with low-level details from the underlying OS - not just path separators. Commented Nov 12, 2016 at 8:26
  • @LittleSanti: The answer is yours by rights. Please claim it if you want the points! Commented Nov 13, 2016 at 5:10
  • @Downvoter: Why the downvote? What didn't you understand? Commented Nov 13, 2016 at 5:12

2 Answers 2

1

Can I manually load up the LinuxFileSystem somehow?

I doubt it, because one JDK distribution is oriented either to Unix or either to Windows. The only chance I think of is that you look for an open source distribution of some UnixFileSystemProvider and import into your application's runtime.

But even in that case, I have my doubts it will work 100%, because a FileSystemProvider class deals with low-level details from the underlying OS - not just path separators, so there is a risk that it won't be compatible over a Windows filesystem.

Sign up to request clarification or add additional context in comments.

Comments

0

Looks like @Little Santi's comment on the question is in fact the answer. If I run:

for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
  System.out.println(provider.getClass().getName());
}

I get:

sun.nio.fs.WindowsFileSystemProvider
com.sun.nio.zipfs.ZipFileSystemProvider

If I interpret this correctly it means I can't use the LinuxFileSystem path methods under Windows but should use commons-io instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.