如何从.jar源代码中获取文件路径

时间:2013-12-23 20:32:18

标签: java jar

我尝试用editor.exe打开file.txt

editor.exe是从编写在Java上的editor.jar转换而来的

我是否有能力从editor.exe的java源代码中获取file.txt绝对文件路径?

enter image description here

1 个答案:

答案 0 :(得分:1)

查看您的main方法;具体地,

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();
            }
        }
    }
}