Bufferedreader解释? [英] Bufferedreader explanation?

查看:135
本文介绍了Bufferedreader解释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.in(标准输入流) - 以字节为单位从键盘获取输入

System.in(Standard input stream)- gets the input from keyboard in bytes

InputStreamReader:将字节转换为Unicode字符/将标准输入转换为与BufferedReader一起使用的reader对象

InputStreamReader: Converts the bytes into Unicode characters/ converts the standard input into reader object to be used with BufferedReader

最后BufferedReader :用于读取字符输入流(输入流读取器)

Finally BufferedReader: Used to read from character input stream(Input stream reader)

String c = br.ReadLine(); - 用于从输入流中读取字符并放入的方法它们在一个字符串中不是逐字节的。

String c = br.ReadLine(); -- a method used to read characters from input stream and put them in the string in one go not byte by byte.

一切都在正确吗?如果有什么不对请更正!

Is everything above right ? Please correct if anything wrong !

推荐答案

几乎就在那里,但是这个:

Nearly there, but this:


String c = br.readLine(); - 一种用于从输入流中读取字符并将其一次性放入字符串中的方法,而不是逐字节。

String c = br.readLine(); -- a method used to read characters from input stream and put them in the string in one go not byte by byte.

它从输入阅读器中读取字符 BufferedReader 不知道流)并且一次返回整行,而不是字符。想想它在层中,并且在 InputStreamReader 层上方,字节的概念不再存在。

It reads characters from the input reader (BufferedReader doesn't know about streams) and returns a whole line in one go, not character by character. Think of it in layers, and "above" the InputStreamReader layer, the concept of "bytes" doesn't exist any more.

另外,请注意,您可以使用 Reader 读取字符块而无需读取行: read(char [],int, int) - readLine()的一点就是它会为你做行结束检测。

Also, note that you can read blocks of characters with a Reader without reading a line: read(char[], int, int) - the point of readLine() is that it will do the line ending detection for you.

(如评论中所述,它也是 readLine ,而不是 ReadLine :)

(As noted in comments, it's also readLine, not ReadLine :)

这篇关于Bufferedreader解释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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