Reputation: 3915
How to get the network path of a file or directory on a windows pc using java? Usually we can see it in shared folder's properties on windows. As shown below.....
Upvotes: 4
Views: 2881
Reputation: 3701
Using Java you can pass net SHARE
command in exec
method of Runtime
class and then parse the outputstream from the Process
class to get the corresponding Network Path of your directory. The output of net SHARE directory_name
command is as follows:
Share name Share
Path C:\Share
Remark
Maximum users No limit
Users
Caching Manual caching of documents
Permission user, FULL
You need to get the value of the Path key from the above output. Following is the pseudo-code of how you can achieve this:
Process process = Runtime.getRuntime().exec("net SHARE directory_name");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringWriter writer = new StringWriter();
String line;
while (null != (line = reader.readLine())) {
writer.write(line);
}
System.out.println(writer.toString());
Upvotes: 2
Reputation: 15271
The API to call is WNetEnumResource. You need to use JNI to call Windows APIs. An example can be found at http://public.m-plify.net/sourcecode/.
Upvotes: 0