Google
 
Web unafbapune.blogspot.com

Wednesday, July 02, 2008

 

Little Java Quiz - File loaded from classpath

Given:
  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();

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?