aspose file tools*
The moose likes Beginning Java and the fly likes Reading file with various object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading file with various object" Watch "Reading file with various object" New topic
Author

Reading file with various object

Nick Allen
Ranch Hand

Joined: Sep 25, 2003
Posts: 47
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


'I need something good to die for, to make it beautiful to live' -QSA
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

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 ]

[How To Ask Questions On JavaRanch]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Reading file with various object