0

On my Windows PC I have my NAS with network path \\nas mounted as Z:\

Finding the root of a file on the filestore with Java 8

Paths.get("Z:\\\\Docs").getRoot();

gives me Z:\

how do I get \\nas

This code is not running as part of the GUI, therefore I do not have access to JFileChooser with currently selected file.

Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
  • Duplicate of https://stackoverflow.com/questions/5722146/how-to-retrieve-the-unc-path-instead-of-mapped-drive-path-from-jfilechooser – Lothar Sep 06 '17 at 14:15
  • Possible duplicate of [Fetching file and path from network using java](https://stackoverflow.com/questions/7991294/fetching-file-and-path-from-network-using-java) – Juan Carlos Mendoza Sep 06 '17 at 14:16
  • I would like a standard pure java solution, is there not a way with nio ? – Paul Taylor Sep 06 '17 at 14:18
  • Hey Paul. Have you tried `toRealPath()`? On Windows that seems to return the network path. – Hendrik Sep 06 '17 at 14:22
  • @hendrik hi, that doesnt seem to work me gives NoSuchFileException – Paul Taylor Sep 06 '17 at 15:07
  • It only works on existing files. So you could try to list a file from that dir, and then call `toRealPath()` on it. – Hendrik Sep 06 '17 at 15:19
  • Hmm, but Z:\Docs is a real file but also Files.exists(p) returns false, why would that be, am I missing something stupid. – Paul Taylor Sep 06 '17 at 16:43
  • @Lothar not a duplicate since I do not have a JFileChooser instance – Paul Taylor Sep 08 '17 at 08:45
  • @hendrik the no such fileexception is some admin/permissions problem I have if run form within Intellij. But if I install as normal I don't get the exception but calling getRealPath() on Z:\ just returns Z:\ – Paul Taylor Sep 08 '17 at 08:54
  • @PaulTaylor Read the answers. The JFileChooser is only the source of the filename, the answers show a couple of ways to get what you need. – Lothar Sep 08 '17 at 09:00
  • @Lothar yes the ShellFolder answer looks like it will work, (though not ideal as I will have to use reflection to avoid it causing problems if on non-windows env). But my point was that the question is different (even if one of the answers may be the same) – Paul Taylor Sep 08 '17 at 09:09

0 Answers0