通过BufferedReader获取流
//package com.nowjava; import java.io.BufferedReader; import java.io.ByteArrayInputStream; /** from N o w J a v a . c o m**/ import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; public class Main { public static void main(String[] argv) { String file = "Main.java"; System.out.println(getStream(file)); } public static InputStream getStream(String file) { File f = new File(file); String total = "";/** from nowjava.com - 时 代 Java**/ try { BufferedReader r = new BufferedReader(new FileReader(f)); String s = r.readLine(); while (s != null) { total += s + "\n"; s = r.readLine(); } r.close(); }