gpt4 book ai didi

java - 在Linux上运行的Java代码中,如何指向共享的Windows文件夹?

转载 作者:太空宇宙 更新时间:2023-11-04 03:32:11 25 4
gpt4 key购买 nike

我有一个共享的 Windows 文件夹:

\servername.domain.com\dir\warname

这是我从 Windows 操作系统上运行的 Java 代码访问它的方法:

// \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 文件夹?

我用谷歌搜索了它,但找不到解决方案。非常感谢任何帮助。

最佳答案

您可能需要在 Linux 上安装 SMB 客户端。请参阅这篇文章了解如何执行此操作:http://www.howtogeek.com/176471/how-to-share-files-between-windows-and-linux/

关于java - 在Linux上运行的Java代码中,如何指向共享的Windows文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32897955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com