public class Employee { private String name; private int age; private int wage; public Employee(){} public Employee(String name,int age,int wage){ this.name=name; this.age=age; this.wage=wage; } public String getName(){ return name; } public int getAge(){ return age; } public int getWage(){ return wage; } public String toString(){ return name+","+age+","+wage; }}public class EmployeeList { private ArrayList<Employee>arr; public EmployeeList(){ arr=new ArrayList<Employee>(); } public void getEmployees(InputStream stream){ DataInputStream in=new DataInputStream(stream); char ch; String name=""; try { while((ch=in.readChar())!=','&&ch!=-1) name+=ch; arr.add(new Employee(name,in.readInt(),in.readInt())); //System.out.println(arr); name=""; } catch (IOException e) { e.printStackTrace(); } } public ArrayList getArr(){ return arr; }}public class TestApp { public static void main(String []args)throws IOException{ EmployeeList employeelist=new EmployeeList(); FileInputStream fin=new FileInputStream("d:\\0001\\student.txt"); employeelist.getEmployees(fin); System.out.println(employeelist.getArr()); } }
添加回答
举报
0/150
提交
取消