1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| package my;
import java.io.File; import java.io.IOException; import java.net.URL;
public class MyUrlDemo { public static void main(String[] args) { MyUrlDemo muDemo = new MyUrlDemo(); try { muDemo.showURL(); } catch (IOException e) { e.printStackTrace(); } }
public void showURL() throws IOException {
File f = new File(this.getClass().getResource("/").getPath()); System.out.println(f);
File f2 = new File(this.getClass().getResource("").getPath()); System.out.println(f2);
File directory = new File(""); String courseFile = directory.getCanonicalPath(); System.out.println(courseFile);
URL xmlpath = this.getClass().getClassLoader().getResource(""); System.out.println(xmlpath);
System.out.println(System.getProperty("user.dir"));
System.out.println(System.getProperty("java.class.path"));
} }
|