0

The thing is that System.getProperty("user.dir"); obtains a path without a current folder. So if class is stored in C:\Users\Nika\workspace\sint\src the output is C:\Users\Nika\workspace\sint. What should I do?

4

4 に答える 4

0

I think this will help you if you want the current working directory:

Getting the Current Working Directory in Java

于 2012-08-21T10:14:07.707 に答える
0

The source directory for a .java is not stored anywhere. You can obtain the based directory of the location of the .class file by getting the protection domain, however this is usally not needed.

Perhaps what you are trying to do is get a file using the class path. In this case I would suggest using ClassLoader.getResourceAsInputStream()

于 2012-08-21T10:14:39.483 に答える
0

Because class loader has current path to it. If yoy create jar then src path would not be valid. so append package name if classes are not in archive

于 2012-08-21T10:15:11.197 に答える
0

Why not use getResource

URL url = Test.class.getClassLoader().getResource(Test.class.getName().concat(".class"));
System.out.println(url.getPath());
于 2012-08-21T10:30:46.527 に答える