Results 1 to 3 of 3
- 03-25-2011, 01:16 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
Read a data from a text file and create an object from these data in this text file
Hi all.. i have a text file it names "person.txt" ...
This is content of person.txt :
***********
m 25 68
g 35 55
g 23 65
m 19 56
m 40 75
***********
if first line is "m" i should create man object, if first line is "g" i should create girl object... other lines show me respectively age and weight.
How can i slove this problem ??
- 03-25-2011, 02:16 PM #2
Member
- Join Date
- Mar 2009
- Posts
- 70
- Rep Power
- 0
What did you try?
- 03-25-2011, 02:36 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
try {
InputStream fis = new FileInputStream("person.txt");
Scanner scanner = new Scanner(fis);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] pieces = line.split(" ");
if(pieces == line.split("m ")){
create man obj.
}
if(pieces == line.split("g ")){
create girl obj.
}
}
scanner.close();
} catch (Exception e) {
System.out.println("There has been some error.");
}
like this but if not correctly and my think is not correct..
i couldn't find how can i do...
Similar Threads
-
Class employee,company,test: Read data from text file.
By jeskoston in forum New To JavaReplies: 4Last Post: 03-01-2011, 01:50 AM -
Write a program that sorts data from a text file and sort them in a file
By danmgz45 in forum New To JavaReplies: 6Last Post: 12-01-2010, 05:31 AM -
JOptionPane with a comboBox with data read from a text file
By rdmapes in forum AWT / SwingReplies: 0Last Post: 11-21-2010, 05:10 PM -
Reading data from a text file
By Cheguvara in forum New To JavaReplies: 2Last Post: 02-02-2010, 02:33 PM -
How to Read data from text file and calculate the values?
By janeansley in forum New To JavaReplies: 40Last Post: 07-04-2008, 08:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks