I am working on an application installer. The user has to provide a file / d开发者_JAVA百科irectory path that will later be created by the application. I need to check if that path is valid (could exists). The problem is that I can not call file.exists() because it might not exist.
I know I could try to create it and then delete it. If it fails, the path is not valid. But is there a better, simpler way? Also, my work around requires special permissions for my installer which is not very good.
Depends on your criteria for a valid path.
- If you mean: path is well formed: Use regular expressions
- If you mean: path is available, try
!file.exists();
A regular expression for Unix based systems could be like this: [^\0]+
Also,you'll find lots more information in this SO Question
精彩评论