Creating an array object from input file
I have a quesion. How to make an array object from an input file. What needs to happen is read data from the file then create an array of appropriate size corresponding to the data entered. The first line in the file is how large the array should be. For instance:
8
3/4
2/3
5/6
.
.
.
7/9
My attempt so far is:
import java.util.*;
import java.io.*;
// create class RationalCollection to implement required methods
// with no instance variable
public class RationalCollection1{
public static void rational(Rationa) {
int n = 0; // number of elements in the array
Rational [] myRationalArray = new Rational [n];
Scanner rationalFile = new Scanner (new File("rational.txt"));
for (int i = 0; i < n; ++i)
{
String rationalString = rationalFile.next();
myRationalArray = new Rational(rationalString);
}
}
The errors returned when compiling the class are:
--Configuration: <Default>--
C:\Documents and Settings\Owner\Desktop\CMIS141\RationalCollection1.java:11: <identifier> expected
public static void rational(Rational[]) {
^
C:\Documents and Settings\Owner\Desktop\CMIS141\RationalCollection1.java:33: ')' expected
}
^
2 errors
maxi04

