IO 输入输出流_java

IO 输入输出流_字符串_02

IO 输入输出流_java_03

package com.baosight.basics;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Scanner;
/**
 * IO流
 * @author chengzheng
 *
 */
public class ReaderWriter {

	public static void main(String[] args) {
//		reader();
		
//		writer("fzy");
		
		scanner();

	}
	
	/**
	 * 从控制台读取输入字符
	 */
	public static void reader() {
		char c=0;
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		System.out.println("输入字符,按0退出");
		do {
			try {
				c=(char)br.read();
				System.out.println(c);
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			
		}while(c!='0');
		
	}
	
	/**
	 * 输入流
	 * @param str
	 */
	public static void writer(String str) {
		BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
		
		try {
			bw.write(str);
			bw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * scanner 输入
	 */
	public static void scanner() {
		String str=null;
		Scanner sc=new Scanner(System.in);
		str=sc.nextLine();
		System.out.println("输入的字符串:"+str);
		sc.close();
	}

}