How can I check if an InputStream is empty without reading from it?

前端 未结 8 935
无人及你
无人及你 2020-12-08 18:10

I want to know if an InputStream is empty, but without using the method read(). Is there a way to know if it\'s empty without reading from it?

8条回答
  •  Happy的楠姐
    2020-12-08 19:03

    How about using inputStreamReader.ready() to find out?

    import java.io.InputStreamReader;
    
    /// ...
    
    InputStreamReader reader = new InputStreamReader(inputStream);
    if (reader.ready()) {
        // do something
    }
    
    // ...
    

提交回复
热议问题