集册 Java实例教程 使用BufferedInputStream读取文件

使用BufferedInputStream读取文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

516
使用BufferedInputStream读取文件


import java.io.BufferedInputStream;/** from nowjava.com - 时代Java**/

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;


public class Main {

  public static void main(String[] args) {

    File file = new File("C://Folder//ReadFile.txt");

    BufferedInputStream bin = null;


    try {

      FileInputStream fin = new FileInputStream(file);

      bin = new BufferedInputStream(fin);

      while (bin.available() > 0) {

        System.out.print((char) bin.read());

      }

    } catch (FileNotFoundException e) {

      System.out.println("File not found" + e);

    } catch (IOException ioe) {

      System.out.println("Exception while reading the file " + ioe);
      /*来自 
       N o w J a v a . c o m*/

    } finally {

      try {
展开阅读全文