Java, help please.

Soldato
Joined
27 Aug 2004
Posts
17,111
Location
Geordieland
Hi guys,

Im having a bit bother. Ive got 2 lines of code that are refusing to compile, both are scanners giving a 'cannot find symbol' error. The 2 lines are (highlited in code also):

Scanner writeGraduate = new Scanner(gradAccounts);
and
Scanner writeNe = new Scanner(newAccounts);

Code:
import java.io.*;
import java.util.*;

class StudentSet
{
	public static void main (String args[]) throws IOException
	{
		TreeSet oldAccounts = new TreeSet();
		TreeSet currAccounts = new TreeSet();
		
		//Define updated information
		TreeSet gradAccounts = new TreeSet();
		TreeSet newAccounts = new TreeSet();
		
		
		Scanner scOld = new Scanner(new FileReader("C:\\Documents and Settings\\Paul Steele\\My Documents\\Junk\\Java\\Hmk2\\oldAccounts.txt"));
		String oldAcc;	
		
		while (scOld.hasNext())
		{
			oldAcc = scOld.next();
			oldAccounts.add(oldAcc);
			System.out.println(oldAcc);
		}
		
		Scanner scCurr = new Scanner(new FileReader("C:\\Documents and Settings\\Paul Steele\\My Documents\\Junk\\Java\\Hmk2\\currAccounts.txt"));
		String currAcc;	
		while (scCurr.hasNext())
		{
			currAcc = scCurr.next();
			currAccounts.add(currAcc);
			System.out.println(currAcc);
		}


		//COMPARE
		
		File writeGrad = new File("C:\\Documents and Settings\\Paul Steele\\My Documents\\Junk\\Java\\Hmk2\\gradAccounts.txt");
		
		PrintWriter writeGr = new PrintWriter(writeGrad);
		
		[B][I]Scanner writeGraduate = new Scanner(gradAccounts);[/I][/B]
		
		while(writeGraduate.hasNext())
		{
			writeGr.println(writeGraduate.next());
		}
		writeGr.close();
		
		
		File writeNew = new File("C:\\Documents and Settings\\Paul Steele\\My Documents\\Junk\\Java\\Hmk2\\newAccounts.txt");
		PrintWriter writeN = new PrintWriter(writeNew);

		[B][I]Scanner writeNe = new Scanner(newAccounts);[/I][/B]
		
		while(writeNe.hasNext())
		{
			writeN.println(writeNe.next());
		}
		writeN.close();
	}
}

Cheers for any help, its got me pulling my hair out.
 
Yes, thanks a lot guys, much appreciated. Got it working.

Never knew you had to use the iterator to do this, so I would never have figured it out had it not been for you guys.

Many thanks.
 
Back
Top Bottom