Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parsing textfile using java

 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mahesh Rana
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gerry Giese
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)!
 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one more thing it's not a distrubuted application.
It runs on only one server
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic