Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with file input and output

Status
Not open for further replies.

hedgracer

Programmer
Mar 21, 2001
186
US
The following code is intended to pull in a file's contents, load into a vector, and print the output to the screen by unloading the vector through the iterator. Unfortunately, I am getting abstract class error messages every time I use the iterator. Here is the code:

private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:

try{
iFile = new File(openFilePath);
BufferedReader fIn = new BufferedReader(new FileReader(iFile));
oFile = new File(saveFilePath);
// BufferedWriter fOut = new BufferedWriter(new FileWriter(oFile));
Vector svector = new Vector();
Iterator isiterator = svector.iterator();


String line = fIn.readLine();
while(line!= null)
{
svector.add(line);
line = fIn.readLine();
}
int vecsize = svector.size();
System.out.println(vecsize);
fIn.close();


while(isiterator.hasNext())
System.out.print(isiterator.next());
}

catch (IOException e)
{
System.out.println(openFilePath + " cannot be opened.");
}
}

Can anyone tell me what is wrong here. I used iterators and vectors in C++ all the time and never had this problem. Thanks for all your help in advance.

Dave Christman
 
Well, first off, there's really no reason to use an iterator with a Vector. You could easily just send it through a for loop and use the get() method to extract the data you need. However, if you are hell bent on using an iterator you might want to take this line: Iterator isiterator = svector.iterator(); and move it down after the population of the Vector.

-gc "I don't look busy because I did it right the first time."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top