I am attempting to have the contents of a URL read and then formatted so it isn't a big jumbled mess anymore. I have already asked the user for input this is where some of my problems begin because I do not know how to make sure the URL they are giving has "http://" included within it. I have already tried to use the URLValidator to know avail. Once that's done I would like to format the URL using my format specifiers that I have learned. Could I have some assistance on this?
I think you will be moved, since that is not a specific Java8 topic. Have you been through the Java Tutorials section? That tells you how to read things. The URL constructor will throw an Exception if you try the wrong format.
If the URL is passed as a String, you can use methods of the String class to find whether it begins with something. You can also search for regular expressions to match URLs and see whether they match your URL name.
What didn't work? We need more info than that.
Read the example in the tutorial link I posted earlier. Adding a few lines from that to your code printed the contents of Johnson's website successfully. Have you tried that sort of thing?
I don't know if this is your question, but the easiest way to fix HTML so it isn't a horrible unreadable mess is to use one of the existing HTML prettifiers. JTidy is a Java product which does that for you, so using that would be far more practical than trying to write your own code to do it.
Oh right, you did mention format specifiers. And yes, I agree that learning to use format specifiers shouldn't be confused with cleaning up messy HTML. Carry on then, and if you have more questions don't hesitate to drop in and ask us.
Destroy anything that stands in your way. Except this tiny ad: