Dmitry Kolesnikovich
Dmitry Kolesnikovich

Reputation: 749

How to get file path from inside .jar source code

I try to open file.txt with editor.exe

editor.exe is converted from editor.jar that is written on Java

Do I have the ability to get file.txt absolute file path from inside java source code of editor.exe?

enter image description here

Upvotes: 0

Views: 269

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201447

Look at your main method; specifically,

public static void main(String[] args) {
    // args[0] should be the path that was requested, in which case you
    // could use
    if (args.length > 0) {
        java.io.File f = new java.io.File(args[0]);
        if (f != null && f.exists()) {
            try {
                System.out.println(f.getCanonicalPath());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Upvotes: 1

Related Questions