This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes parsing inputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "parsing inputStream" Watch "parsing inputStream" New topic

parsing inputStream

kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
i'm writing a small program to that connects to a URL and reads it



URL yahoo new URL("");
URLConenection yc = yahoo.openConnection();
BufferedReader in new BufferedReader(new InputStreamReader(yc.getInputStream()));

//...more code to readLine and then print etc

can someone please tell me of a method in or otherwise, that could be used to get a certain type of information from an input stream say a certain link or a some known string, instead of just the whole page!!!

[ October 11, 2005: Message edited by: kwame Iwegbue ]

Who dares, wins! (SAS motto)
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Depends on what the "certain type of information" is and what the contents of the input stream is. For example if the content of the stream is a gif file, what would you want to get?
Please describe the input data?
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
say i want to get only a particular string of text from the page, or only a particular link which is already known to me, so that i can print only that string of text or maybe even follow only that link from the page...

[ October 11, 2005: Message edited by: kwame Iwegbue ]
[ October 11, 2005: Message edited by: kwame Iwegbue ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Depending on the complexity of the parsing you want to do, you can use IntputStreamTokenizer, classes in java.util.regex, or a full blown parser such as javacc. No matter which of these you choose, you will ened up reading the complete content of the InputStream (or close to it).


Java API Documentation
The Java Tutorial
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
You should probably google for an open source Java html parser...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
Thanks for your suggestions. They were quite useful. Does anyone know where to find tutorials on 'parsing HTML" I've done a google search, but it seems only one article at java.sun came close to what I need. it was addressing Swing HTML parser. but can I find more articles? specifically, I'm trying to parse out text from a html file
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114

You can find an HTML parser here:

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: parsing inputStream