0

I need to get a File object (not a Stream) to pass to a library. I am getting "URI is not hierarchical". I have seen some solutions but they either are rather inefficient or use external libraries.

File myFile = new File(MyClass.class.getClassLoader().getResource(dir).toURI())

By the way, I need the object to pass to

Lucene FSDirectory.open(myFile)

Any idea?

Altober
  • 922
  • 2
  • 13
  • 27
  • What's the url actually look like? – markspace Jan 18 '15 at 17:27
  • Not sure, it is an issue in the server with PIG, when I run it on hadoop it works fine. – Altober Jan 18 '15 at 17:28
  • A basic debugging strategy is to print intermediate calculations out so you can inspect them. Putting some logging statements in this routine with a log-level of "FINE" seems like a wise investment. – markspace Jan 18 '15 at 17:31
  • possible duplicate of [Java resource as file](http://stackoverflow.com/questions/676097/java-resource-as-file) – mindas Jan 19 '15 at 14:06

1 Answers1

0

URI not hierarchical need to use File class for a method

may be a possible solution. Essentially just copies the file to a temp file then uses that. I was getting this error since I was using a JAR.