java的read()_Java Reader read()方法
Java Reader read()方法
java.io.Reader.read()?讀取一個字符。該方法將一直阻塞,直到有字符可用,發(fā)生I/O錯誤或到達流的末尾為止。
1 語法
public int read()
2 參數(shù)
無
3 返回值
此方法以0到65535(0x00-0xffff)范圍內(nèi)的整數(shù)返回讀取的字符,如果已到達流的末尾,則返回-1。
4 示例
package com.yiidian;
/**
* 一點教程網(wǎng): http://www.yiidian.com
*/
/**
* java.io.Reader.read()方法的例子
*/
import java.io.*;
public class Demo {
public static void main(String[] args) {
String s = "Hello World";
// create a new StringReader
Reader reader = new StringReader(s);
try {
// read the first five chars
for (int i = 0; i < 5; i++) {
char c = (char) reader.read();
System.out.print("" + c);
}
// change line
System.out.println();
// close the stream
reader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
輸出結(jié)果為:
Hello
總結(jié)
以上是生活随笔為你收集整理的java的read()_Java Reader read()方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: mysql yn 字段类型_mysql常
- 下一篇: java连接sqlserver2008_
