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?
Asked
Active
Viewed 136 times
0

nicks
- 2,161
- 8
- 49
- 101
-
1What do you mean by _current folder_? The name of the directory in which the JVM is executing? If so `new File(".").getName()`. – hmjd Aug 21 '12 at 10:14
-
See Java File class - it is all there – Germann Arlington Aug 21 '12 at 10:15
-
I think you'll have to clarify what you want. – maba Aug 21 '12 at 11:04
-
Look. If the JAR file's full name is `D:\Projects\Compiled\Other\MyJar.jar`, I want program to output `D:\Projects\Compiled\Other\MyJar.jar`. Just that. – nicks Aug 21 '12 at 11:05
4 Answers
0
I think this will help you if you want the current working directory:
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()

Peter Lawrey
- 525,659
- 79
- 751
- 1,130
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

Nirmal- thInk beYond
- 11,847
- 8
- 35
- 46
0
Why not use getResource
URL url = Test.class.getClassLoader().getResource(Test.class.getName().concat(".class"));
System.out.println(url.getPath());

Amit Deshpande
- 19,001
- 4
- 46
- 72