我正在覆蓋自定義類中的android.webkit.WebViewClient
方法shouldInterceptRequest(WebView view, String url)
。在某些情況下,url
參數指向加密的本地文件,格式爲file:///path/to/file.extension
。我需要將字符串url
轉換爲java.io.File
來解密它。
如何可靠地將url
參數轉換爲有效路徑以傳遞到new File(path)
?將URL字符串轉換爲java.io.File
0
A
回答
1
使用下面的代碼:
new File(new URL(url).toURI());
但如果網址不分層,這是你的情況下,將只工作。 (例如,如果URL指向JAR文件中的文件,則不能這樣做)。
0
文件構造函數接受URI,讓你可以試試:
File file = new File(new URL("file:///path/to/file.extension").toURI());
System.out.println(file);
Output:
\path\to\file.extension
相關問題
- 1. 將url轉換爲字符串
- 2. IOS將URL字符串轉換爲NSString?
- 3. 如何將字符串轉換爲url?
- 4. 將com.google.api.services.drive.model.File轉換爲java.io.File
- 5. 將FormFile轉換爲Java.io.File
- 6. 將url編碼的字符串轉換爲python unicode字符串
- 7. 將字符串轉換爲字符串
- 8. 將字符串轉換爲字符串
- 9. 將字符串轉換爲字符串
- 10. 將字符串轉換爲int,int轉換爲字符串
- 11. 將字符串轉換爲「_」
- 12. 將字符串轉換爲
- 13. 將字符串轉換爲?
- 14. 將部分url字符串轉換爲完整的url字符串
- 15. Password中的特殊字符將URL轉換爲字符串
- 16. 將轉換器映射字符串轉換爲字符串
- 17. 將字符串轉換爲字符ascii
- 18. Java - 將字符串轉換爲字符[]
- 19. C++ - 將字符串轉換爲字符
- 20. 將字符*轉換爲字符串
- 21. 將字符串轉換爲字符
- 22. 將字符串轉換爲const *字符
- 23. 將字符[]轉換爲字符串
- 24. InfixToPostfix將字符轉換爲字符串
- 25. 將字符串轉換爲字符
- 26. 將char字符串轉換爲字符
- 27. 將字符串轉換爲字符
- 28. PHP字符串轉換爲URL編碼
- 29. (URL)字符串不能轉換爲JSONObject
- 30. 將vfs url字符串轉換爲url對象
我不認爲這會工作,因爲參數'url'不是'java.net.Url',它是一個' java.lang.String'。 – 2015-02-24 16:55:00
更正,錯過了 – Crazyjavahacking 2015-02-24 16:56:01