java - Get the path when run from terminal or command line -
i trying create programme run terminal or command line. have supply file name in arguments. want able path in programme run , append file name it. this:
public static void main(string[] args) { scanner scanner = new scanner(system.in); if (args.length > 0) { if (args[0] instanceof string && !args[0].equals(null)) { if (args[0].equals("compile")) { system.out.println("file compile:"); string filename = scanner.next(); string path = /*get path here*/ + filename; file textfile = new file(path); if (textfile.exists()) { compiler compiler = new compiler(textfile); compiler.compile(); } else { system.out.println("file doesn't exist"); } } } } }
this should work you:
paths.get("").toabsolutepath().tostring()
you can test by:
system.out.println("" + paths.get("").toabsolutepath().tostring());
java
No comments:
Post a Comment