读取TXT文件

public static List<Map<String, String>> readTXT(String path)
   throws IOException {
  //根据路径新建文件对象
  File file = new File(path);
  //转换为字节流
  FileInputStream fis = new FileInputStream(file);
  //将字节流转换为字符流
  InputStreamReader is = new InputStreamReader(fis, "GBK");
  BufferedReader br = new BufferedReader(is);
  List<Map<String, String>> list = new ArrayList<Map<String, String>>();
  Map<String, String> map = null;
  String line = null;
  //每次读取一行数据
  while ((line = br.readLine()) != null) {
   if (line != null && !(line.equals(""))) {//判断该行数据是否为空

}

}

}

posted @ 2017-01-19 16:10  bake056  阅读(176)  评论(0编辑  收藏  举报