1/0流的典型使用方式
1.缓冲输入文件
package com.java.io; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class BufferedInputFile { public static String read(String pathname) throws IOException { BufferedReader in = new BufferedReader(new FileReader(new File(pathname))); String s; StringBuilder sb = new StringBuilder(); while((s = in.readLine())!=null){ sb.append(s + "\n") ; } in.close(); return sb.toString(); } public static void main(String[] args) throws IOException { System.out.print(read("src/com/java/io/BufferedInputFile.java")); } }
console将当前的BufferedInputFile.java文件原封不动的打印出来;
时间: 2024-11-05 17:04:10