URI for local resources

前端 未结 3 910
孤独总比滥情好
孤独总比滥情好 2021-01-08 00:46

In Java can I create a URI for a file located locally in the hard drive? If so, how should it be constructed?

相关标签:
3条回答
  • 2021-01-08 01:04

    Try below:

    URI uri = new URI("file:///C:/other/mydir/myfile.txt");
    
    0 讨论(0)
  • 2021-01-08 01:06

    Look at File documentation:

    File has a constructor, which takes URI as a parameter, and it also has method toURI() if you want to get URI from existing file. You can play with that to understand how the things should be done.

    You can also read about URI (it's not a java term). There is an example in Wikipedia:

    file:///home/username/RomeoAndJuliet.pdf

    0 讨论(0)
  • 2021-01-08 01:22
    URI uri = new URI("file:///filename.txt");
    

    If you're using Windows:

    URI uri = new URI("file:///C:/fun/filename.txt");
    
    0 讨论(0)
提交回复
热议问题