I am working on a project, and one requirement is that if the second argument to the main method starts with " / " (for linux), it should consider it as an absolute path (not a problem), but if it does not start with " / " , it should get the current working path of the class and add the given argument to it.
I can get the class name in several ways: System.getProperty("java.class.path") , new File(".") And getCanonicalPath() , and so on ...
The problem is that this only gives me the directory where the packages are stored - that is, if I have a class stored in " .../project/this/is/package/name ", it will give me only " /project/ "and ignores the name of the package in which the .class files actual .class files .
Any suggestions?
EDIT: Here is an explanation taken from the exercise description
sourcedir can be either absolute (starting with "/"), or relative to where we start the program
sourcedir is the given argument for the main method. how can i find this way?
java eclipse package classname
La bla bla Mar 15 2018-12-15T00: 00Z
source share