我需要监控 Amazon S3 上的目录以检查是否有任何新文件添加到该目录。我尝试使用 Java NIO Watch Service,但它无法正常工作。如果我在提供的 S3 路径中使用以下语法:
String pathToMonitor="file://https://abc/dir"; //Line1
Path path=Paths.get(new URL(pathToMonitor).toURI()); //Line2
Boolean isFolder=(Boolean) Files.getAttribute(file, "basic:isDirectory", LinkOption.NOFOLLOW_LINKS); //Line3
然后我收到以下错误:
java.nio.file.FileSystemException: \\https\abc\dir: The network path was not found.
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:53)
at sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:38)
at sun.nio.fs.AbstractBasicFileAttributeView.readAttributes(AbstractBasicFileAttributeView.java:168)
at sun.nio.fs.AbstractFileSystemProvider.readAttributes(AbstractFileSystemProvider.java:92)
at java.nio.file.Files.readAttributes(Files.java:1961)
at java.nio.file.Files.getAttribute(Files.java:1866)
如果我file://
从路径中删除前缀,则会生成以下错误:
Exception in thread "main" java.nio.file.FileSystemNotFoundException: Provider "https" not installed
at java.nio.file.Paths.get(Paths.java:147)
如果我将“Line2”修改为,Path path=Paths.get("https://abc/dir");
则生成以下跟踪:
Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 5: https://abc/dir
at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
at java.nio.file.Paths.get(Paths.java:84)
请让我知道我在这里做错了什么以及是否可以使用 Java 监视服务来监视此类 Web 资源,或者是否有任何其他框架/api。
谢谢