Convert a file: URL to a java.io.File . First tries to parse the URL's toExternalForm as a URI and create the File object from that URI. If this fails, just uses the path part of the URL. This handles URLs that contain spaces or other unusual characters, both as literals and when enco
(URL theURL)
| 638 | * File. |
| 639 | */ |
| 640 | public static File fileFromURL(URL theURL) throws IllegalArgumentException { |
| 641 | try { |
| 642 | URI uri = new URI(theURL.toExternalForm()); |
| 643 | return new File(uri); |
| 644 | } |
| 645 | catch(URISyntaxException use) { |
| 646 | try { |
| 647 | URI uri = new URI(theURL.getProtocol(), null, theURL.getPath(), null, null); |
| 648 | return new File(uri); |
| 649 | } |
| 650 | catch(URISyntaxException use2) { |
| 651 | throw new IllegalArgumentException("Cannot convert " + theURL + " to a file path"); |
| 652 | } |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * Same as {@link java.io.File#listFiles(java.io.FileFilter)} |
no test coverage detected