2011-11-04 101 views

回答

2

你可以做this.This工作

ClassLoader loader = this.getClass().getClassLoader(); 
URL url = loader.getResource("resource name"); 
String[] filePath = null; 
String protocol = url.getProtocol(); 
if(protocol.equals("jar")){ 
    url = new URL(url.getPath()); 
    protocol = url.getProtocol(); 
} 
if(protocol.equals("file")){ 
    String[] pathArray = url.getPath().split("!"); 
    filePath = pathArray[0].split("/",2); 
} 

文件所需=新的文件(文件路径[1]);

相关问题