0

Possible Duplicate:
Is there a way in Java to determine if a path is valid without attempting to create a file?

I'm trying to let the user enter the path where he wants something to be saved. so basically i open an editor, and let him enter the path...

but how can i check if the entered string is a valid path?

if the user forgets to type in a "/" at the end - its not a problem, i can manually check for that...

but i cant manually check for everything:

a space at the end (/folder /)

question marks.

greater than - less than symbols (/folder:->/

(back)slashes \folder\

and all that stuff

is there a convenient way in java to check for that?

Community
  • 1
  • 1
RazorHail
  • 431
  • 1
  • 5
  • 17

1 Answers1

1

Generic Java file is a directory or exists, from this answer:

File file = new File("c:\\cygwin\\cygwin.bat");
if (!file.isDirectory())
   file = file.getParentFile();
if (file.exists()) {
    ...
}

However, Android (question tagged as android), I'll have to look into...

Community
  • 1
  • 1
Charles Goodwin
  • 6,402
  • 3
  • 34
  • 63
  • 1
    An answer is not the place for posting "possible duplicates" comments. Also, he did not explicity say anything about Android in his question, although you write (in most cases) in Java for Android phones, so the tagging is correct. – Wroclai Jul 20 '11 at 23:30
  • @Pompe de velo: Android and standard Java have different APIs, so how can that be correct without making assumptions? This is not a syntax related question, it is an API question. – Charles Goodwin Jul 20 '11 at 23:33
  • @Pompe de velo: You are right, I have just found the duplicate process. For me, hiding "is a duplicate" under "does not belong here" is pretty unintuitive since the question does belong here, but it has been asked already. – Charles Goodwin Jul 20 '11 at 23:34
  • Yes, although, if he is tagging for Android, and at the same time mentions file, which one are you going to assume? However, the solution is the same, even though Java and Android have different API:s. – Wroclai Jul 20 '11 at 23:36