I am trying to read a file with 8 columns of data and store each string of data into an array, but I keep getting cannot find symbol error for employee.length. I put 8 elements for each string within the row. Please help me by explaining what I am doing wrong. Code:
Scanner scan = new Scanner(new FileReader ("payrollData.dat"));
String employee[] = new String[8];
while(scan.hasNext())
{
for(int i = 0; i < employee.length(); i++)
{
employee[i] = scan.next();
}
}
System.out.println(employee);8
Its employee.length
and not employee.length()
. In case of arrays, length is a final variable, not a method.
And use Arrays.toString(employee)
to print employees properly. System.out.println(employee)
will just print the reference address.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.