Java中的InputStream read()如何确定要读取的字节数? [英] How does InputStream read() in Java determine the number of bytes to read?

查看:812
本文介绍了Java中的InputStream read()如何确定要读取的字节数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://docs. oracle.com/javase/7/docs/api/java/io/InputStream.html#read()

文档说:从输入流中读取一定数量的字节,并将其存储到缓冲区数组b中."

The doc says "Reads some number of bytes from the input stream and stores them into the buffer array b.".

InputStream如何用Java中的read()确定该字节数?

How does InputStream read() in Java determine that number of bytes?

推荐答案

缓冲区数组具有定义的长度,将其称为n. read()方法将读取1到n个字节.除非检测到EOF,否则它将阻塞直到至少一个字节可用为止.

The buffer array has a defined length, call it n. The read() method will read between 1 and n bytes. It will block until at least one byte is available, unless EOF is detected.

这篇关于Java中的InputStream read()如何确定要读取的字节数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆