我的代码是:
File file = new File( "T:\\sub1\\15a12f0103135510.jpg");
long lastModified = file.lastModified();
System.out.println( "last modified: " + lastModified);
System.out.println( "done: " + file.exists());
最后修改返回 0。file.exists 返回 false。但是,我可以通过 Windows 资源管理器访问和打开文件,没问题。直接访问网络共享也不起作用(在代码中)。尝试过 smb - 也显示错误。我是机器上的管理员用户。可能是什么原因?我可以检查什么?
如果我执行以下操作:
URL url = new URL( "file://host/share/sub1/15a12f0103135510.jpg");
url.openStream();
我收到以下错误:
java.io.IOException: sun.net.ftp.FtpProtocolException: Welcome message: 501 Proxy unable to contact ftp server
at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:308)
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:400)
at java.net.URL.openStream(URL.java:1045)
at apiteest.ApiTest.main(ApiTest.java:24)
Caused by: sun.net.ftp.FtpProtocolException: Welcome message: 501 Proxy unable to contact ftp server
at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1022)
at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1005)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:294)
... 3 more
Suppressed: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
at sun.net.ftp.impl.FtpClient.readServerResponse(FtpClient.java:420)
at sun.net.ftp.impl.FtpClient.readReply(FtpClient.java:497)
at sun.net.ftp.impl.FtpClient.issueCommand(FtpClient.java:539)
at sun.net.ftp.impl.FtpClient.close(FtpClient.java:1131)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:303)
... 3 more
Exception in thread "main" java.io.IOException: sun.net.ftp.FtpProtocolException: Welcome message: 501 Proxy unable to c
ontact ftp server
更新: 代码在从 powershell 执行时有效,但在以管理员身份启动的 powershell 执行时无效(尽管是同一用户)。即使该服务在同一用户下运行,它也不适用于服务。为什么会这样?以及如何为服务启用共享(可能还有映射驱动器)?