Computer Science Canada

Creating an array with a text document

Author:  IntelMaster [ Tue May 25, 2010 5:50 pm ]
Post subject:  Creating an array with a text document

Hi,

I want to take the numbers from a text document and make an array out of it, but for some reason my program is not working. After gathering the arrays I want to calculate the median for the numbers. Here is my program so far:
Java:

                String amounta=jTextField8.getText();
                int amount=Integer.parseInt(amounta);
                int sum=0;
                try {
                        FileInputStream in = new FileInputStream("numbers.txt");
                        BufferedReader br = new BufferedReader(new InputStreamReader(in));
                       
                        int numbers[] = new int[amount];
                        for (int count = 0; count==amount; count++){
                                numbers[count] = Integer.parseInt(br.readLine());
                                sum=sum+numbers[count];
                                System.out.println(sum/amount );
                        }
                        in.close();       
                }catch (Exception e)
                {
                       
                }

Author:  Insectoid [ Tue May 25, 2010 6:04 pm ]
Post subject:  RE:Creating an array with a text document

Make sure your file is really 'numbers.txt' and not 'numbers.txt.txt'. Happens a lot (to me). Damn you Windows, I'll type my own extensions!

Other than that, I can't think of what's wrong (due in no small part to my inability to read Java without my head exploding).

Author:  DemonWasp [ Tue May 25, 2010 6:49 pm ]
Post subject:  RE:Creating an array with a text document

@Insectoid: you can force Windows Explorer to always show extensions. This is one of the first things I do whenever I set up Windows, because foobar.bmp.jpeg has always been a stupid, irritating problem.


: