File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 8708
    
    6

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 ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading file with various object
 
Similar Threads
writer's block on assignment, any help?
Reading File contents to a String
sorting
problem in formatting date
assignment help