Hi,
I was creating a program which list the files in directory name, which is passed from the command line.
I have observed the File constructor accepts paths with forward slash "\" at the end of the directory path. I mean the following are valid arguments to File constructor. and works fine
1) C:\Program Files
2) C:\Program Files\
But, while running from command line (windows platform) I need to use quotes (") around the directory path, is the path contains spaces (Eg:- "C:\Program Files").
"C:\Program Files" (with quotes) is a valid argument to File constructor.
And "C:\Program Files\" (with quotes) IS NOT a valid argument to File constructor.
Here is the coding I used validate this scenario.
{code}
if((args[0].charAt(args[0].length()-1)=='"'))
if(args[0].charAt(args[0].length()-2)=='\\'){
System.out.println("Please remove: \\ from the path");
return;
}
....
....
File f = new File(args[0]);
args[0].charAt(args[0].length()-1) is correctly returns double quote (").
The issue I am facing is, so I am not able to check the shash.
args[0].charAt(args[0].length()-2) DOES NOT return slash character '\\' (actually, returns the character before the slash)
Please help me if there is any work around solution