4.17
基本字符流
public String readLine() //从输入流读取一行字符,BufferedReader的方法
public void newLine() //从输出流写入一行结束的标志,BufferedWriter的方法
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class FileToUnicode {
public static void main(String args[]){
try{
FileInputStream fis = new FileInputStream("file1.txt");
InputStreamReader dis = new InputStreamReader(fis);
BufferedReader reader = new BufferedReader(dis);
String s;
while ((s = reader.readLine())!= null){
System.out.println("read:"+s);
}
dis.close();
}catch(IOException e){
System.out.println(e);
}
}//main()
}//class
实现将字符串从标准输入通道读取字符串信息然后将其输出
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CharInput {
public static void main(String args[]) throws IOException {
String s;
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(ir);
while ((s = in.readLine())!= null){
System.out.println("Read:"+ s );
}
}
}