如何從jar:file:/C:/Program%20Files/test.jar!/foo/bar
轉到File
指向C:/Program Files/test.jar
?如何將「jar:file」URI轉換爲Jar文件的路徑?
4
A
回答
7
下面的代碼對我的作品(基於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())
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]);
相關問題
- 1. 將文件路徑轉換爲URI
- 2. 將文件路徑轉換爲URI
- 3. 將URI轉換爲路徑
- 4. 如何將文件路徑轉換爲Android中的內容Uri?
- 5. 如何將文件夾路徑轉換爲內容Uri?
- 6. Ionic2:將文件選擇器URI轉換爲文件路徑
- 7. 將文件路徑轉換爲文件URI?
- 8. 將URI轉換爲Windows路徑格式
- 9. Android - 將URI轉換爲棒棒糖上的文件路徑
- 10. 如何將文本轉換爲路徑?
- 11. 如何將路徑轉換轉換爲路徑中的ImageBrush?
- 12. 如何將(.JAR)文件轉換爲UML?
- 13. 如何將apk文件轉換爲jar
- 14. 將NSURL轉換爲AppleScript文件路徑
- 15. Objective-C - 如何將文件路徑轉換爲shell符合文件路徑
- 16. 如何將windows文件夾路徑轉換爲linux文件夾路徑
- 17. 將React-Native轉換爲Android的實際路徑內容:// URI爲實際路徑
- 18. Python模塊路徑如何轉換爲文件系統路徑?
- 19. 如何將文件路徑轉換爲django中的url
- 20. 如何將Assembly.CodeBase轉換爲C#中的文件系統路徑?
- 21. 如何將Illustrator文件轉換爲WPF的路徑
- 22. 在生成文件中將Cygwin路徑轉換爲Windows路徑
- 23. 如何將Mac路徑轉換爲Windows?
- 24. 將'../../'轉換爲'路徑/路徑'
- 25. 將路徑轉換爲UNC路徑
- 26. c#將路徑轉換爲新路徑\\
- 27. 將路徑轉換爲絕對路徑
- 28. 將HTTP路徑轉換爲UNC路徑?
- 29. 如何將字符串轉換爲文件路徑(SD卡路徑)? android
- 30. 如何將Android.Net.Uri路徑轉換爲xamarin中的物理路徑?