繁体   English   中英

在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代码访问它的方式:

// \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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM