This content has been marked as final. Show 13 replies
You can use a java.util.Scanner.
Personally, I'd do it like this:
1) read the file line-by-line. You can use Scanner for this, or java.io.BufferedReader.
2) make parsing a single line part of the class that encapsulates this information. Suppose all this data is for a Person class. Then in Person.java you'd have a constructor or method that looks like this:
(you can use a shorter method name there, of course)
public Person(String formattedString); //or public static Person createPersonObjectFromFormattedDataString(String formattedString);
Altternatively, you could create a PersonFactory class in the same package as Person.
Actually you could put the stuff in part (1) in the same package (or source file) as well.
One you get a line of data, you can use regular expressions, or Scanner again, or StringTokenizer, or other stuff. I'd start with regexps though (java.util.regex).
Thanks very much to all of you,
For some time I've been busy with j2me and have forgotten some j2se tools like regex package.
You are right it seems the regex is the best way to go.
I don't want to seem ungrateful or any thing but actually I'm not so good in creating regex patterns and I have a question, Is it possible to read for example date section completely as a string not separate tokens and also it seems it will have a time section with ":" character. I think it must be possible but I'm not sure.
Any how thanks very much.
I don't want to seem ungrateful or any thing butAlready happens with sabre's regex.
actually I'm not so good in creating regex patterns
and I have a question, Is it possible to read for
example date section completely as a string not
and also it seems it will have a timeYes it is.
section with ":" character. I think it must be
possible but I'm not sure.
i don't want to re-invent the wheel, i just don't know com.Ostermiller.util Java Utilities !
you may use CSV file for your datas and create aWhy re-invent the wheel -
CSVParser (using the tips given in this thread to
read the file),
thanks for the info
my text file is
303 04222530987 12/12/2007 12:32:23 00:01:00 2
302 04222492528 12/25/2007 12:52:36 00:12:32 3
how can i separate the above datas in the file into the folloving datas
please rply me with sample coding
any comments is honestly appreciated
Read the java.lang.String API. It offers lot of useful methods, under each a split() method.
And in the future, please start new topic for each independent question instead of hijacking others topics and resurrecting old topics.