我在 Windows 8.1 上的 Tomcat 7.0.57 上有一个 Web 应用程序将其作为服务运行,它被指示复制本地网络共享目录中的文件,例如\\Network_machine\Shared_folder,但它无法这样做。
我无需任何身份验证即可访问 Windows 资源管理器中的共享文件夹,因为它具有所有人阅读的权限。以下代码检查目录是否存在:
String sourceURL = this.servletContext.getInitParameter("sourceURL");
log.debug("---------->Source reports directory : " + sourceURL);
File sourceDir = new File(sourceURL);
log.debug("---------->Source directory exists : "+sourceDir.exists());
if (sourceDir.exists()) {
String files[] = sourceDir.list();
log.debug("----------> Total files in source dir :" + files.length);
List<String> newFiles = new ArrayList<String>(Arrays.asList(files));
newFiles.removeAll(processedFiles);
log.debug("----------> Latest files in source dir :" + newFiles.size());
File file = null;
if (newFiles.size() > 0) {
for (String fileName : newFiles) {
file = new File(sourceURL + Constants.FILE_SEP + fileName);
latestSourceFiles.add(file);
}
}
} else {
log.debug("Source reports directory " + sourceURL + " is not found");
}
附加信息:
日志 - 源目录存在并返回“FALSE”。
最佳答案
正如 Kenneth 所说,您需要将共享文件夹映射到一个驱动器,然后直接写入该驱动器。
http://windows.microsoft.com/en-us/windows/create-shortcut-map-network-drive
关于java - 无法读取网络共享文件夹上的文件[webbapp 是作为服务的 tomcat],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27942760/