Hi everyone,
I require some help for this project I am currently working on. Basically what I have to do is read from two text files, then calculate some numbers from both files (eg: add the numbers and average them) and after that, write the results to a another file. I have written a bit of code to read from the files but I am stuck at the moment.
import java.io.*;
import java.util.*;
public class Read
{
public static void main(String [] args)
{
BufferedReader input;
String line;
String [] subject = new String[3];
int i = 0;
try
{
FileReader fr = new FileReader("Description.txt");
input = new BufferedReader(fr);
while ((line = input.readLine()) != null)
{
StringTokenizer tokenizer = new StringTokenizer(line, ", \t");
String token;
while (tokenizer.hasMoreTokens())
{
token = tokenizer.nextToken();
System.out.println(token);
// subject[i] = token;
// System.out.println(subject[i]);
// i++;
}
}
input.close();
}
catch (IOException e)
{
System.err.println(e);
}
}
}
You see, I am trying to put each line of the text file into an array. Here is an example of the file:
Introduction to Software
Assignment, 100, 10
Tutorial, 100, 10
I know every line there are 3 strings. But what I am unsure of is how to put each line into a different array.
I hope someone can help. Thank you :)