Java通过java.io.FileInputStream读取txt文本


Java通过java.io.FileInputStream读取txt文本

package com;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class TestIO {
 public static void main(String[] args) {
  FileInputStream in = null;
  try {
   in = new FileInputStream("test.txt");
   int c;
   c = in.read();
   while (c != -1) {
    System.out.print((char) c);
    c = in.read();
   }
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   System.out.println(e.getMessage());
  } finally {
   try {
    in.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }
}

其中test.txt内为英文字符串,放在eclipse项目文件夹根目录下,对于中文需要做编码处理。

Java 8 中 HashMap 的性能提升

Java 8 的 Nashorn 引擎

Java 8简明教程

本文永久更新链接地址:

相关内容

    暂无相关文章