package com.sf._03_字节输入流;


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;

public class Test3 {
    /**
     * 已知文档中现内容
     * name=zhangsan,age=10,email=123
     *
     * 把内容封装到Student 对象中打印student
     * @param args
     */
    public static void main(String[] args) throws IOException {
        //1 创建字节输入流
        FileInputStream fileInputStream = new FileInputStream(new File("d:\\a.txt"));
        //2 读取数据
        byte[] buffer = new byte[100];
        int len = fileInputStream.read(buffer);
        String str = new String(buffer, 0, len);
        System.out.println(str);
        // 要做事情拿到zhangsan   10  123 把设置student 中
        //name=zhangsan,age=10,email=123
        Student student = new Student();
        String[] strArr = str.split(",");
        System.out.println(Arrays.toString(strArr));
        for (String s : strArr) {
            // s  : name=zhangsan
            // [name,zhangsan]
            String[] split = s.split("=");
            if(s.contains("name")){
                student.setName(split[1]);
            }
            // [age,10]
            if(s.contains("age")){
                student.setAge(Integer.valueOf(split[1]));
            }
            // [email,132]
            if(s.contains("email")){
                student.setEmail(split[1]);
            }
        }
        System.out.println(student);
        // 关闭
        fileInputStream.close();
    }
}
