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

前端 未结 8 956
无人及你
无人及你 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条回答
  •  猫巷女王i
    2020-12-08 18:48

    public void run() {
        byte[] buffer = new byte[256];  
        int bytes;                      
    
        while (true) {
            try {
                bytes = mmInStream.read(buffer);
                mHandler.obtainMessage(RECIEVE_MESSAGE, bytes, -1, buffer).sendToTarget();
            } catch (IOException e) {
                break;
            }
        }
    }
    

提交回复
热议问题