Search Blog

Search duranek.blogspot.com

Sunday, November 30, 2008

Physical Location of a file in classpath?

  1. a file with a given name;
  2. the file is located in the file system;
  3. the file can be loaded via the classpath;
How can the code figure out the physical location (ie absolute path) of the file ?

(Don't peek if you want to give it a try!)

Answer:
    String filePath = Thread.currentThread()

.getContextClassLoader()

.getResource(filename)

.getFile();


( From http://hansonchar.blogspot.com/)

No comments: