Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

valid URL

Status
Not open for further replies.

DeSn

Programmer
Nov 20, 2001
111
BE
How can I test if an URL is valid?

F.e. new URL("file:\\test\t.txt") give me an URL object while the path "test\t.txt" isn't a valid path.
How can i test this?
 
Hi,

I have noticed that any URL beginning "file:\\" will return valid object. Most odd! If it is on the local file system then the following code will work :

import java.io.File;

..
..

File testFile = new File ("\test\t.txt");
if (!testFile.exists()) {

//File doesnt exist
}
else {

// File does exist
}

..
..

Hope this helps.

Cheers,

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top