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

使用FileInputStream读取文件

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

432
使用FileInputStream读取文件

import java.io.*;/**n o w j a v a . c o m**/

 

public class Main {

  public static void main(String[] args) {


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

    int ch;

    StringBuffer strContent = new StringBuffer("");

    FileInputStream fin = null;

   

    try{

      fin = new FileInputStream(file);

      while( (ch = fin.read()) != -1)

        strContent.append((char)ch);

      fin.close();

    } catch(FileNotFoundException e) {//时 代      J a v a   公   众 号 - nowjava.com 提 供

      System.out.println("File " + file.getAbsolutePath() + " could not be found on filesystem");

    }catch(IOException ioe) {

      System.
展开阅读全文