java - 无法读取网络共享文件夹上的文件[webbapp 是作为服务的 tomcat]

标签 java tomcat service file-copying local-network

我在 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/

相关文章:

java - 如何让java反射也采用依赖类?

java - 递归装箱算法无法扩展

java - 在Java中,将内部本地数组提取到外部是内存效率高还是速度优势?

asp.net-mvc - 从 Windows 服务执行 Quartz.NET 作业

java - 让 Dexguard 不删除未使用的资源

tomcat - 什么是 Tomcat 等同于这些 WebLogic 设置

java - Tomcat 服务器错误 - 端口 8080 已被使用

java - Tomcat负载均衡序列化异常PersistenceExceptionTranslationInterceptor : lazy initialization exception

android - 长按 EditText 时触发广播接收器

python - Uwsgi 在作为服务运行时不会加载应用程序