I have an application that receives a path as a command line argument. The path can contain spaces, so it can be sended with quotes. I need to verify if this path is correct, so I execute 'exists' method from 'File' class:
public static void main (String... args) {
System.out.println("arg=" + args[0]);
File f = new File(args[0]);
System.out.println("exists=" + f.exists());
}
When I run the application with the follow arguments, I obtain this results (assume that "c:\folder" exists). Pay attention with final slash and quotes:
> java Test c:\folder
args=c:\folder
exists=true
> java Test c:\folder\
args=c:\folder\
exists=true
> java Test "c:\folder"
args=c:\folder
exists=true
> java Test "c:\folder\"
args=c:\folder
exists=false
I don't understand what's happens with last example. First in args result don't print final slash and then File class say that path doesn't exists. Second example without quotes works well. Argument path has a free user edition, so it's possible that can include quotes (if path has folder with spaces) and a final slash.