App下載
首頁javapathJava I/O - 如何將文件路徑轉(zhuǎn)換為URL

Java I/O - 如何將文件路徑轉(zhuǎn)換為URL

我們想知道如何將文件路徑轉(zhuǎn)換為URL。
 

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
  public static void main(String args[]) throws MalformedURLException {
    File file = new File("The End");
    URL url2 = file.toURI().toURL();
    System.out.printf("Good url %s%n", url2);
  }
}