permaculture playing cards
The moose likes Beginning Java and the fly likes Using strings, etc. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using strings, etc." Watch "Using strings, etc." New topic

Using strings, etc.

Anita Raj

Joined: Mar 02, 2003
Posts: 7
I want to print out ALL links present in a page (the page is in HTML). Can someone tell me how to do this...what's wrong with this code...anything! Thanks.

[ March 23, 2003: Message edited by: Anita Raj ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Does it compile?
Does it run?
Does it work?
Does it throw an exception?

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Anita Raj

Joined: Mar 02, 2003
Posts: 7
When I compiled it, these errors came:

java.lang.StringIndexOutOfBoundsException: String index out of range: -729
at java.lang.String.substring(
at Proj.ReturnURL.ParsePage(
at Proj.ReturnURL.main(
Exception in thread "main"
[ March 23, 2003: Message edited by: Anita Raj ]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Do you think it's very efficient to allocate an array of 1,000,000 bytes? Would it make more sense to wrap your FileInputStream with a BufferedInputStream so that you can do readLine()? And shouldn't you be using FileReader to read character data?
What does your program do if it doesn't find the string it is searching for (either "a href=" or "/")? What does the indexOf return when it doesn't find a String? What effect would that have on your program? How do you ever get to the end of your while loop?

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
I agree. Here's the link:
subject: Using strings, etc.
It's not a secret anymore!