Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem creating File object using a URI  RSS feed

 
Dan Mortimer
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a java.io.File object by using the File constructor that takes a URI. Here's the code:

try {
URI uri = new URI("http://cms.rexam.net/stellent/groups/public");
File dir = new File(uri);

}
catch(URISyntaxException urise) {
System.out.println("Invalid URI");
urise.printStackTrace();
}

And the error I get is:

Exception in thread "main" java.lang.IllegalArgumentException: URI scheme is not
"file"
at java.io.File.<init>(Unknown Source)
at FileNameSearch.getMatchingFiles(FileNameSearch.java:43)
at FileNameSearch.main(FileNameSearch.java:57)

By looking at the API, it looks like I can create a URI object by passing in a String. It then should be possible to create a File object by passing in a URI - what have I missed?

Any suggestions gratefully received...

Thanks!
 
J Kneeland
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to be using the file scheme to do that. new URL("file://....."); The file is supposed to be on the same machine and it is just another way of giving the location on the system. You probably need to figure out another way instead of using Files.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!