No, you can't. InputStream
is designed to work with remote resources, so you can't know if it's there until you actually read from it.
You may be able to use a java.io.PushbackInputStream
, however, which allows you to read from the stream to see if there's something there, and then "push it back" up the stream (that's not how it really works, but that's the way it behaves to client code).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…