文件char操作与从键盘读入行

 import java.io.*;

class StreamTest
{
 public static void main(String [] args) throws Exception
 {
  /*从文件读入char
  FileOutputStream fos = new FileOutputStream("1.txt");
  //OutputStreamReader isr = new OutputStreamReader(fos);
  OutputStreamWriter osw = new OutputStreamWriter(fos);
  BufferedWriter bw = new BufferedWriter(osw);
  bw.write("cccccccccccccccccccc");
  bw.close();
  
  FileInputStream fis = new FileInputStream("1.txt");
  InputStreamReader isr = new InputStreamReader(fis);
  BufferedReader br = new BufferedReader(isr); 
  char [] ch = new char[100];
  br.read(ch);
  System.out.println(ch);
  br.close();*/
  
  //从键盘输入
  InputStreamReader isr = new InputStreamReader(System.in);
  BufferedReader br = new BufferedReader(isr);
  String str;
  while((str = br.readLine()) != null)
   System.out.println(str);
  
  br.close();
  }
 
}

你可能感兴趣的:(java自学,exception,string,import,class,null)