Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filling an array from a file input stream

Martin Kyle
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am trying to pass the file input for the excel.txt file to an array for a college project. The code I have so far is below. I can get it to read the file but get lost when trying to pass it to an array. It should also be able to read each line of the text file and ask the user for an input (int). Please can someone help me....

import java.util.*;

public class courseQuestions {

public static void main(String[] args) {

int grade;
int count = 0;
int runTot = 0;


FileReader file = new FileReader("D:\\Java Files\\TNA Project\\TNA Project\\excel.txt");
BufferedReader buff = new BufferedReader(file);

boolean eof = false;
while (!eof) {
String line = buff.readLine();
if (line == null)
eof = true;



} catch (IOException e) {
System.out.println("Error -- " + e.toString());

Vector question = new Vector();

String [] course = {file};

for( int i = 0; i < course.length; i++ )

Iterator it = question.iterator();
while ( it.hasNext() )
System.out.println( );
grade = EasyIn.getInt();
runTot += grade;
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To create an array for your Strings, you need to know its size.
The constructor String [] course = {file}; is very new for me - may it be wrong?

Count the lines while reading, and create your array with the result.
You have to read the file twice - the first time for counting, the second time to fill the array.

And please use code-tags.
Hit the code-button before pasting code, and after.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic