开发者

Read elements from a file and store them in ArrayList as Objects

I have a file contains (string, int, floating, char)

12

1.8

a

John

23.5

I want to read them an store them in an ArrayList. My ArrayList type is 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.ad开发者_如何学运维d(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? You should be displaying C and not A. If not, please let us know what is the Exception.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜