4
에서 을 가리키는 File
으로 어떻게 이동합니까?"jar : file"URI를 Jar 파일의 경로로 변환하려면 어떻게해야합니까?
에서 을 가리키는 File
으로 어떻게 이동합니까?"jar : file"URI를 Jar 파일의 경로로 변환하려면 어떻게해야합니까?
(How do I get just the jar URL from a jar: URL containing a "!" and a specific file in the jar? 기준) :
URL url = new URL("jar:file:/C:/Program%20Files/test.jar!/foo/bar");
JarURLConnection connection = (JarURLConnection) url.openConnection();
File file = new File(connection.getJarFileURL().toURI())
당신은 이걸이
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);
}
파일이 필요 = 새로운 파일을 작동 할 수 있습니다 (FilePath를 [1]);