1,将内容读取到map集合中:

  1. public class Text02 {
  2. public static void main(String[] args) throws IOException {
  3. //创建缓冲输入流:
  4. BufferedReader bos = new BufferedReader(new FileReader("G:\\xxx\\student.txt"));
  5. //创建map集合
  6. HashMap<String, Integer> map = new HashMap<>();
  7. //将读取的行内容保存;
  8. String line;
  9. //循环读取
  10. while ((line = bos.readLine()) != null){
  11. String[] split = line.split("=");
  12. map.put(split[0],Integer.parseInt(split[1]));
  13. }
  14. //map遍历:
  15. map.forEach((s,value) -> {
  16. System.out.println(s+"::"+value);
  17. });
  18. }
  19. }