只是想知道是否有一种方法可以从使用JFileChooser选择的文件中返回UNC路径。我要选择的文件将驻留在具有UNC路径的映射驱动器上。现在,我似乎只能拉回映射驱动器的驱动器号。
最佳答案
从https://stackoverflow.com/users/715934/tasoocoo
我最终找到了执行NET USE命令的解决方案:
filePath = fc.getSelectedFile().getAbsolutePath();
Runtime runTime = Runtime.getRuntime();
Process process = runTime.exec("net use");
InputStream inStream = process.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line = null;
String[] components = null;
while (null != (line = bufferedReader.readLine())) {
components = line.split("\\s+");
if ((components.length > 2) && (components[1].equals(filePath.substring(0, 2)))) {
filePath = filePath.replace(components[1], components[2]);
}
}