Ruang penulis
← Kembali ke jurnal
Core API

How do I get the path from where a class is loaded?

This examples shows how to get a path name or location from where our class is loaded. package org.kodejava.lang; public class CodeSourceLocation { public static void main(String[] args) { CodeSourceLocation csl = new CodeSourceLocation(); csl.getCodeSourceLocation(); } private void getCodeSourceLocation() { // The location from where the class is loaded. System.out.println("Code source location: " + getClass().getProtectionDomain().getCodeSource().getLocation()); […]

DWayan · 28 Sep 2008 · 1 menit baca

Artikel oleh Wayan · Sumber: Kode Java ↗

Terjemahan artikel ini belum tersedia. Isi asli ditampilkan.

This examples shows how to get a path name or location from where our class is loaded.

package org.kodejava.lang;

public class CodeSourceLocation {
    public static void main(String[] args) {
        CodeSourceLocation csl = new CodeSourceLocation();
        csl.getCodeSourceLocation();
    }

    private void getCodeSourceLocation() {
        // The location from where the class is loaded.
        System.out.println("Code source location: " +
            getClass().getProtectionDomain().getCodeSource().getLocation());
    }
}

The code snippet print the following output:

Code source location: file:/F:/Wayan/Kodejava/kodejava-example/kodejava-lang/target/classes/
← Jelajahi catatan lainnya