• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading file with various object

 
Nick Allen
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to read a file with both House objects and Agent objects. This is what I have for the method:

public void readInFile() throws Exception
{

System.out.println("Enter file name you wish to use");
try
{
String fyle = kb.readLine();
File usersFile = new File(fyle);
if(usersFile.exists())
{
BufferedReader fr = new BufferedReader(new FileReader(fyle));
String line = "";
String bits[];
while ((line = fr.readLine()) != null)
{
bits = line.split(":");

if(bits[0] = "House")
{
House[ctr++] = new House(bits[1],bits[2]);
}
if(bits[0] = "Agent")
{
Agent[ctr++] = new Agent(bits[1]);
}
}

fr.close();
}
}
i keep getting constructor errors, where it says "new Agent..." or "new House...", Can't resolve symbol errors for House and Agent, and that i need a boolean instead of bits[0] in my if statement
 
Joe Ess
Bartender
Posts: 9295
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nick Allen:

and that i need a boolean instead of bits[0] in my if statement

if(bits[0] = "House")

This bit of code is assigning the value of "House" to the array location 0. What you need to do is compare the value of array location 0 to the value "House"


i keep getting constructor errors, where it says "new Agent..." or "new House...", Can't resolve symbol errors for House and Agent

Have you created and compiled your House and Agent classes? If so then you have a classpath issue.
BTW, it's called a compiler. A constructor is what you call on a class to create a new instance. Just so we're on the same sheet of music.
[ November 06, 2003: Message edited by: Joe Ess ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic