I want to check if a resource key exists before get it from resources. I use TemplateControl.GetGlobalResourceObject to get the resource.
Is it possible?
Thank you.
Java provides a simple boolean method, file. exists() that doesn't require any parameters to check the relevant file on a given path.
Java Language HttpURLConnection Check if resource exists If you are just checking if a resource exists, it better to use a HEAD request than a GET. This avoids the overhead of transferring the resource. Note that the method only returns true if the response code is 200 .
To find a file in the classpath we have created a method, File findFileOnClassPath(final String fileName) that reads a fileName and returns the File. The method is described below: It uses the System. getProperty(String key) to find the classpath of java and the path separator used.
GetGlobalResourceObject
returns object
type. You can always check if it is null
before you cast it (to a string for example) and use it in subsequent logic.
Be careful that (string)TemplateControl.GetGlobalResourceObject
will throw
an InvalidCastException
that needs to be handled.
For reference: TemplateControl.GetGlobalResourceObject Method (String, String)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With