疯狂java


您现在的位置: 疯狂软件 >> 新闻资讯 >> 正文

Java输入输出流操作


 

  //1 输入基本字节流

  InputStream is = new FileInputStream("c:/1.txt");

  //2 输入加强字节流

  BufferedInputStream bis = new BufferedInputStream(is);

  //3 输入基本字符流

  Reader r = new FileReader("c:/1.txt");

  //4 输入加强字符流

  BufferedReader br = new BufferedReader(r);

  String ss = br.readLine();

  //1 输出基本字节流

  OutputStream os = new FileOutputStream("c:/1.txt");

  //2 输出加强字节流

  BufferedOutputStream bos = new BufferedOutputStream(os);

  //3 输出基本字符流

  Writer w = new FileWriter("c:/1.txt");

  //4 输出加强字符流

  BufferedWriter bw = new BufferedWriter(w);

  bw.newLine();

  //5 输出加强字符流,可直接打开文本文件,println()比newLine()更好用

  PrintWriter pw = new PrintWriter(w);

  PrintWriter pw2 = new PrintWriter("c:/1.txt");

  pw.println();

  pw.println("1");

  //文件节点流:FileInputStream、FileReader、FileOutputStream、FileWriter、PrintWriter