在 Linux 上的 Java 代码 运行 中,如何指向共享的 Windows 文件夹?
In Java code running on Linux, how to point to a shared Windows folder?
我有一个共享 Windows 文件夹:
\servername.domain.com\dir\warname
这就是我在 Windows OS 上从 Java 代码 运行 访问它的方式 OS:
// \dir
String directory = getInitParameter ("directory");
// /warname
final String contextPath = this.getServletContext().getContextPath();
// \dir/warname
directory += (directory.endsWith("/") ? contextPath.substring(1) : contextPath);
// //servername.domain.com/\dir/warname
directory = "//" + getDatabaseServerName() + (directory.startsWith("/") ? "" : "/") + directory;
// \servername.domain.com\dir\warname
File shareDir = new File(directory);
if (!shareDir.exists()) {
if (!shareDir.mkdirs()) {
throw new Exception ("Error: " + shareDir + " does not exist and could not be created.");
}
}
从现在开始,我可以访问 \servername.domain.com\dir\warname 并写入它。
如果此代码在 Linux 服务器上运行,这就是我得到的:
directory: //servername.domain.com/\dir/warname
shareDir: /severname.domain.com/\dir/warname
然后是上面的exp。将被抛出:
java.lang.Exception: Error: /servername.domain.com/\dir/warname does not exist and could not be created.
因此它尝试创建一个新目录但失败了。
如何从 Linux 指向相同的共享 Windows 文件夹?
我 Google 进行了搜索,但未能找到解决方案。非常感谢任何帮助。
您可能需要在 Linux 上安装 SMB 客户端。请参阅这篇文章了解如何做到这一点:http://www.howtogeek.com/176471/how-to-share-files-between-windows-and-linux/
我有一个共享 Windows 文件夹:
\servername.domain.com\dir\warname
这就是我在 Windows OS 上从 Java 代码 运行 访问它的方式 OS:
// \dir
String directory = getInitParameter ("directory");
// /warname
final String contextPath = this.getServletContext().getContextPath();
// \dir/warname
directory += (directory.endsWith("/") ? contextPath.substring(1) : contextPath);
// //servername.domain.com/\dir/warname
directory = "//" + getDatabaseServerName() + (directory.startsWith("/") ? "" : "/") + directory;
// \servername.domain.com\dir\warname
File shareDir = new File(directory);
if (!shareDir.exists()) {
if (!shareDir.mkdirs()) {
throw new Exception ("Error: " + shareDir + " does not exist and could not be created.");
}
}
从现在开始,我可以访问 \servername.domain.com\dir\warname 并写入它。
如果此代码在 Linux 服务器上运行,这就是我得到的:
directory: //servername.domain.com/\dir/warname
shareDir: /severname.domain.com/\dir/warname
然后是上面的exp。将被抛出:
java.lang.Exception: Error: /servername.domain.com/\dir/warname does not exist and could not be created.
因此它尝试创建一个新目录但失败了。
如何从 Linux 指向相同的共享 Windows 文件夹?
我 Google 进行了搜索,但未能找到解决方案。非常感谢任何帮助。
您可能需要在 Linux 上安装 SMB 客户端。请参阅这篇文章了解如何做到这一点:http://www.howtogeek.com/176471/how-to-share-files-between-windows-and-linux/