N.S.Karthik
N.S.Karthik

Reputation: 487

( Strict ) Relative Path Verification

If Relative path needs to be validated for the path

ClassLoader.getSystemResourceAsStream("Configurator/initlizer/init.xml").available()

Question

if the Relative path is valid ~ avaliable() returns int value greater then '0'

if the Relative path is invalid ~ avaliable() returns int value ??

Upvotes: 0

Views: 44

Answers (1)

Hpn4
Hpn4

Reputation: 119

The method available() of a stream doesn't tell you if your path is valid or not. It just sends you the number of bytes that can be read.

Here the javadoc of the available() method in InputStream class.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

You know if your path is valid or not just by calling ClassLoader.getSystemResourceAsStream("yourPath");. Because this method will return null if the resource can't be found.

The javadoc of getSystemResourceAsStream():

@return An input stream for reading the resource; {@code null} if the resource could not be found, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.

Upvotes: 2

Related Questions