从文件中读取元素,并将其作为对象存储在ArrayList中
||
我有一个文件包含(字符串,整数,浮点数,字符)
12
1.8
一种
约翰
23.5
我想读取它们并将它们存储在ArrayList中。我的ArrayList类型是object。但是,当我运行它时,仍然会出现异常。
public static void main(String [] args) throws IOException{
try{
FileReader a=new FileReader(\"src/SET_A.txt\");
Scanner b=new Scanner(a);
ArrayList<Object> c=new ArrayList<Object>();
while(b.hasNextLine())
{
Object d=b.nextInt();
c.add(d);
}
System.out.println(\"The content of arraylist is: \" + a);
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
没有找到相关结果
已邀请:
1 个回复
需复