aspose file tools*
The moose likes Servlets and the fly likes parsing textfile using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "parsing textfile using java" Watch "parsing textfile using java" New topic
Author

parsing textfile using java

Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
I am assigned a project to rewrite MFC based C++ parser program.
What this program does is to parse the given input text file and creates five different neatly formatted output text files using the data from input files.
I have to write in JAVa.,i don't know what to use, should i use
servlets or pure java.
Do any of you have any code like this parser program in java
please let me know.

Bhasker Reddy
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Bhasker
A couple of questions first:
How is the program run, meaning is it run as a client/server, (web based app)? Or is it a standalone app on someones computer or distributed? Since it was an MFC app I assume it is the later. In that case you're probably looking at a straight Java application to run on a specific computer (ie not served from a web server).
Start off looking at the java.io package and the various classes in there - I can't be real specific because I've not done a lot of stuff with io, and much of what you do will depend on exactly what type of parsing you need to do to the original file.
hope that gives you at least a start point.

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform


Dave
Mahesh Rana
Ranch Hand

Joined: Sep 05, 2001
Posts: 139
Well, you can have same code work as an application as well as
servlet.
But Dave is right.
Define your requirments first. The file I/O is a breeze in Java.
------------------
SCJP2


SCJP2
Gerry Giese
Ranch Hand

Joined: Aug 02, 2001
Posts: 247
Bkasker - check out regular expressions for text parsing. If you can figure out the syntax (it's tough at first) you'll be glad you did. I used regular expressions in Perl to split out data files and it made for short and simple programs. Check out javaregex and ORO especially.
http://www.google.com/search?q=java+regular+expression
BTW - you're probably a little confused on servlets, so let me give you a hint. You can use regular Java classes in a servlet. Whoa! The implication is that you write your parsing class to read the input file, parse it using String/StringBuffer classes or regular expression packages, and write out the resulting files.
You would probably pass into the constructor the full-path location of the input file and the full-path where you want the resulting files stored. Then you simply call that class from your user interface or controller, which would be what provides the parameters for the constructor. This could be a GUI application with AWT/Swing, a command-line/console application (which would allow for scripting/cron jobbing), or a servlet. You could even write all three to use the same parsing class!
That's the beauty of OO and Java - division of work to allow for re-use, flexibility, and portability. Good luck with your progam(s)!


CJP (Certifiable Java Programmer), AMSE (Anti-Microsoft Software Engineer)
Author of Posts in the Saloon
Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
We wan't to make it a java server which runs automatically.
It picks up files(input) from a directory, as soon as some one
places the file there and then sequences the file and generates
5 output files. It should run as a cron job. We also want to
create a web administration tools, which we can use to stop
and start the server.
I think java.text and java.io are the key packages that i need
for this project.
IF anyone wants to look further i can email you the text file
that i will be getting and the ouput files that i need to generate
Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
one more thing it's not a distrubuted application.
It runs on only one server
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: parsing textfile using java