getInputStream().read
时间: 2023-10-25 13:35:11 浏览: 18
getInputStream().read() 是 Java 中 InputStream 类的一个方法,它用于从输入流中读取一个字节的数据。该方法会一直阻塞直到有数据可读,或者抛出异常。它的返回值是一个 int 类型的整数,表示读取到的字节数据。如果返回值为 -1,则表示已经到达输入流的末尾。一般情况下,我们可以使用 while 循环不断调用 read() 方法来读取输入流中的数据,直到读取完毕或者遇到异常。
相关问题
Android tcp socket.getInputStream read
在Android中,使用TCP Socket进行网络通信时,可以使用如下代码读取输入流(InputStream)中的数据:
```java
Socket socket = new Socket("host", port);
InputStream inputStream = socket.getInputStream();
byte[] buffer = new byte[1024];
int len = inputStream.read(buffer); // 阻塞读取输入流中的数据
String data = new String(buffer, 0, len);
```
其中,`inputStream.read(buffer)`是一个阻塞方法,会一直等待输入流中有数据可读取,直到读取到数据或者发生异常才会返回。读取到的数据将会存储在`buffer`数组中,返回值`len`表示实际读取到的字节数。最后,可以将字节数组转换为字符串类型的数据,以便后续处理。需要注意的是,这里的读取操作是在主线程中执行的,如果需要避免阻塞主线程,可以将读取操作放到子线程中执行。
EasyExcel.read(file.getInputStream()).sheet().doRead();
引用\[1\]和\[2\]中的代码片段展示了使用EasyExcel库读取Excel文件的示例。在这些示例中,通过调用`EasyExcel.read(file.getInputStream())`来创建一个Excel读取器,然后使用`.sheet()`方法指定要读取的工作表,最后使用`.doRead()`方法执行读取操作。这些代码片段中的`UserExcelListener`和`UploadDataListener`是自定义的监听器类,用于处理读取到的Excel数据。这些监听器类需要继承`AnalysisEventListener`类,并实现其中的方法来处理读取到的数据。
所以,`EasyExcel.read(file.getInputStream()).sheet().doRead();`这行代码的作用是创建一个Excel读取器,读取文件流中的Excel数据,并执行读取操作。具体的读取操作会根据使用的监听器类来处理。
#### 引用[.reference_title]
- *1* *3* [EasyExcel](https://blog.csdn.net/weixin_49075777/article/details/114358036)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Java 实现EasyExcel对Excel的简单写操作和读操作](https://blog.csdn.net/qq_45315910/article/details/107364525)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)