使用 Java 在映射的网络驱动器中创建文件夹

发布于 2024-10-10 05:20:26 字数 203 浏览 0 评论 0原文

我正在尝试使用 Java 创建一个到映射网络驱动器 Z: 的文件夹,

不幸的是该文件没有被创建。这就是我正在做的:

File file = new File("Z:/file1");
file.mkdir();

此代码在不使用映射网络驱动器时有效。这是在Windows环境下。

有什么想法吗?

I'm trying to create a folder to a mapped network drive Z: using Java

Unfortunately the file is not getting created. This is what I'm doing:

File file = new File("Z:/file1");
file.mkdir();

This code works when not using mapped network drive. This is on Windows environment.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不语却知心 2024-10-17 05:20:26

好吧,我明白了。 Tomcat 在 Windows 2003 Server 下运行。据我发现,当Tomcat在Windows服务下启动时,由于某种原因它无法访问映射的网络驱动器。
使用 UNC 路径对我有用。

File myFile = new File("\\\\server\\shared\\input");
myFile.mkdir();

我能够在该服务器上的映射网络驱动器上创建一个文件夹。

Ok I figured this out. Tomcat is running under Windows 2003 Server. According to what I found is that when Tomcat is started under the Windows Services, for some reason it doesn't have access to the mapped network drive.
Using UNC paths worked for me.

File myFile = new File("\\\\server\\shared\\input");
myFile.mkdir();

I was able to create a folder on the mapped network drive on that server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文