使用InputStream和FileInputStream逐块读取文本
import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream;//时 代 J a v a 公 众 号 - N o w J a v a . c o m public class InputStreamTest { public static void main(String[] args) throws IOException{ InputStream inputStream = null; try{ inputStream = new FileInputStream("C:/input.txt"); byte[] bytes = new byte[1024]; int index; while((index = inputStream.read(bytes)) != -1){ System.out.println("index ="+index); } }