FileNotFoundException thrown when the file does exists

后端 未结 4 2121
心在旅途
心在旅途 2021-01-06 17:36

I\'m facing this strange problem.

I\'m trying to read a file that is located in another machine as a shared resource:

\\\\remote-machine\\dir\\MyFile         


        
相关标签:
4条回答
  • 2021-01-06 17:50

    I had a similar problem once. I think it has to do with the way java resolves remote files URI's. Try the following and see if it works:

    File:////remote-machine/dir/MyFileHere.txt

    I used the folowing example to verify the existence of a file in shared folders in my box and worked:

    public static void main(String[] args) throws URISyntaxException{
        URI uri = new URI(args[0]); //args[0] = File:////remote-machine/dir/MyFileHere.txt
        File f = new File(uri);
        System.out.print(String.format("File %1$s Exists? %2$s", args[0],f.exists()));
    }
    
    0 讨论(0)
  • 2021-01-06 18:01

    Is the shared resource protected by a username and password? And if so, is your application engine running as that user? If your application engine is running as a Windows Service, the Windows service cannot be running as the "Local System Account". This account cannot access the network. You must configure your service to run as a user that has the rights to access the shared drive.

    0 讨论(0)
  • 2021-01-06 18:07

    Have you checked the event logs on the server to see if it is being rejected? it could be that the program is running under a different user account than you think.

    I'm not familiar with Java, but i know with some programs i've written i've had to allow Network Service to access the resources.

    Actually i see that you have now ticked an answer as the correct one. oh and it was the same as my answer :) Cool!

    0 讨论(0)
  • 2021-01-06 18:14

    Double check that the file is REALLY Called "MyFileHere.txt" and not "MyFileHere.txt.txt" If you are hiding the extention of the file this is an easy mistake to miss

    0 讨论(0)
提交回复
热议问题