Friday 2 March 2012

get directory of current class in java

URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
String path = URLDecoder.decode(url.getPath(), "utf-8"); //important: if directory has space or chinese words
File file= new File(path);
System.out.println("directory is: " + file.getPath());

No comments:

Post a Comment