开发者

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

开发者 https://www.devze.com 2023-02-25 03:40 出处:网络
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.

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

精彩评论

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