So, this is probably just something really minor that I'm missing, but I've racked my brain debugging this for awhile and havn't found a fix, so maybe you guys can help me out.
import java.io.*;
import java.util.*;
public class VectorDemo
{
public static void main(
String[] args)
{
int arrayCount = 0;
int charValue = 0;
PrintWriter fileOutput = null;//create the PrintWriter object before the try{ so it will not die at the } ending the try
try
{
BufferedReader inputStreamCounter = new BufferedReader(new FileReader("PetRecords.txt"));
String line = inputStreamCounter.readLine();
while(line != null)//count the total number of lines being read from the file
{
arrayCount++;
line = inputStreamCounter.readLine();
}
inputStreamCounter.close();//close the stream so it can be reopened to write to the vector
BufferedReader inputStream = new BufferedReader(new FileReader("PetRecords.txt"));
Vector<String> petVector = new Vector<String>(10);
for(int x = 0; x < arrayCount - 1; x++)//gather data from file into the vector
{
petVector.addElement(inputStream.readLine());
}
for(int x = 0; x < arrayCount - 1; x++)
{
if(petVector.elementAt(x) == " ") //removes all whitespace lines from the vector
{ petVector.removeElementAt(x); }//makes name be at index 0 + 3n, age at 1 + 3n, and weight at 2 + 3n
}
public static void sort(int charValue)//create method to check value of letters in name to alphabetize.
{//recurve if name(0) == name2(0)
for(int x = 0; x < petVecor.size() - 2; x += 3)
{
if(petVector.elementAt(x).charAt(charValue) > petVector.elementAt(x + 3).charAt(charValue))
{
String vectorTempOne = petVector.elementAt(x);//copies the pet record from x to temporary variables
String vectorTempTwo = petVector.elementAt(x + 1);//to transfer x+3 to x, and x to x+3
String vectorTempThree = petVector.elementAt(x + 2);
petVector.setElementAt(petVector.elementAt(x + 3), x);//copying the record starting at x+3 to x
petVector.setElementAt(petVector.elementAt(x + 4), x + 1);
petVector.setElementAt(petVector.elementAt(x + 5), x + 2);
petVector.setElementAt(vectorTempOne, x + 3);//copying the record that was put in temp vars to x+3
petVector.setElementAt(vectorTempTwo, x + 4);
petVector.setElementAt(vectorTempThree, x + 5);
}
if(petVector.elementAt(x).charAt(charValue) == petVector.elementAt(x + 3).charAt(charValue))
{
charValue++;
VectorDemo.sort(charValue);
}
}
}
VectorDemo.sort(0);
fileOutput = new PrintWriter(new FileOutputStream("PetRecordOutput.txt"));
for(int x = 0; x < petRecord.size() - 2; x += 3)
{
fileOutput.println(petRecord.elementAt(x) + "\n" + petRecord.elementAt(x + 1) + "\n" + petRecord.elementAt(x + 2));
}
fileOutput.close(); //close the file stream when done
}
catch(FileNotFoundException e)
{
System.out.println("File PetRecords.txt not found.");
}
catch(IOException e)
{
System.out.println("Problem reading from file.");
}
}
}
Basically I'm reading in a "Pet Record" from a file, which is just a name on one line, age on next line, and weight on the line after that. I then need to sort all the record by name alphabetically, and output it to a file. I can't debug the rest of it until I get this error fixed.
I'm getting an illegal start of expression on line 42 (which is my sort method).
[ October 30, 2006: Message edited by: Lucas Laws ]