FileNotFoundException thrown when the file does exists

后端 未结 4 2161
心在旅途
心在旅途 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()));
    }
    

提交回复
热议问题