Check if file exists on Internet

Hi,

I’ve been trying to find a way to check if a file exists on the internet using Unity Java. All references I find is about checking for a local file. For example:

if (System.IO.File.Exists("myfile.txt"))
{
    print("File Found!");
}

From what I can make out, the above method is not compatible with WWW. Does anyone have any suggestions?

Thanks

Paul

Check the error returned by the WWW, or use a WWW replacement (find in the Asset Store)

Me likes something like this:

	static public bool WebFileExists (string uri) {
		long fileLength = -1;
		WebRequest request = HttpWebRequest.Create(uri);
		request.Method = "HEAD";
		WebResponse resp = null;
		try {
			resp = request.GetResponse();
		} catch {
			resp = null;
		}
		if (resp != null) {
			long.TryParse(resp.Headers.Get("Content-Length"), out fileLength);
		}
		return fileLength > 0;
	}