I'm trying to get current path of system. I use this statement for this purpose :
String currentPath = System.getProperty("user.dir"); When I run this statement For Example from E:\. I get E:\
but when I run from desktop I get C:\users\zavarghadim\desktop. The last slash (\) missed. Why this happen? In both type I need last slash c:\users\zavargadim\desktop\
Can anyone help me to solve this problem?
E:\is the root directory ofE:drive,c:\users\zavargadim\desktopis thedesktopdirectory, they essentially mean the same thing. You could useFile(String, String)to construct a directory/path combination if that's what you neededuser.dircan have or lack a trailing slash depending on any number of factors (how the user entered the directory, operating system, shell options, whatever). Do not rely on it to have a trailing slash or not, and if you need to use that, instead validate it yourself.