Java中I/O的字符流InputStreamReader和OutputStreamWriter_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Java中I/O的字符流InputStreamReader和OutputStreamWriter

Java中I/O的字符流InputStreamReader和OutputStreamWriter

 2018/10/22 12:18:31  andrew7676  程序员俱乐部  我要评论(0)
  • 摘要:1.InputStreamReader和OutputStreamWriter的使用(Decorator)BufferedReader.readLine()方法可以一次读取一行。importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.InputStreamReader;importjava
  • 标签:Java
1. InputStreamReader和OutputStreamWriter的使用(Decorator)
class="java" name="code">
BufferedReader.readLine()方法可以一次读取一行。

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class StreamTest {
    public static void main(String[] args) throws Exception {
        FileOutputStream fos = new FileOutputStream("file.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osw);
        bw.write("http://www.google.com");
        bw.write("\n");
        bw.write("http://www.baidu.com");
        bw.close();
        FileInputStream fis = new FileInputStream("file.txt");
        InputStreamReader isr = new InputStreamReader(fis);
        BufferedReader br = new BufferedReader(isr);
        String str = br.readLine();
        while(null != str){
            System.out.println(str);
            str = br.readLine();
        }
        br.close();
    }
}

public class StreamTest2 {
    public static void main(String[] args) throws Exception {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String str;
        while(null != (str = br.readLine())){
            System.out.println(str);
        }
        br.close();
    }
}
发表评论
用户名: 匿名