1,将内容读取到map集合中:
public class Text02 {
public static void main(String[] args) throws IOException {
//创建缓冲输入流:
BufferedReader bos = new BufferedReader(new FileReader("G:\\xxx\\student.txt"));
//创建map集合
HashMap<String, Integer> map = new HashMap<>();
//将读取的行内容保存;
String line;
//循环读取
while ((line = bos.readLine()) != null){
String[] split = line.split("=");
map.put(split[0],Integer.parseInt(split[1]));
}
//map遍历:
map.forEach((s,value) -> {
System.out.println(s+"::"+value);
});
}
}