[英]Read elements from a file and store them in ArrayList as Objects
I have a file contains (string, int, floating, char) 我有一个文件包含(字符串,整数,浮点数,字符)
12 12
1.8 1.8
a 一种
John 约翰
23.5 23.5
I want to read them an store them in an ArrayList. 我想读取它们并将它们存储在ArrayList中。 My ArrayList type is object.
我的ArrayList类型是object。 But, still I get exceptions when I run it.
但是,当我运行它时,仍然会出现异常。
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();
}
}
Are you displaying the File or the Contents of ArrayList? 您正在显示文件还是ArrayList的内容? You should be displaying C and not A. If not, please let us know what is the Exception.
您应该显示C而不是A。如果不是,请告诉我们什么是例外。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.