+ 1

Paste text content from webpage into java?

First off, I am very new and have little experience. What I want to do with my little code project, is to copy almost everything from an article online into my system.out.println(" here "). However I only get loads of errors, maybe because the text appears on many lines? Idk, appreciate any help :)

16th May 2017, 9:43 PM
Theodor Norill Kvalvaag
Theodor Norill Kvalvaag - avatar
3 Antworten
+ 4
Are there any quotes in the text you are trying to copy? That'll mess with the string you're trying to output. Also keep in mind System has a capitol S. System.out.println("message"); If it is quotes that are causing the errors you can handle them with the escape character \. Ex/ System.out.println("A quote: \" "); Output: A quote: " (Place \ before the quote you want to output)
16th May 2017, 10:43 PM
Rrestoring faith
Rrestoring faith - avatar
0
Thanks for the help, I'll have a look at it! might be some quotes.
16th May 2017, 10:59 PM
Theodor Norill Kvalvaag
Theodor Norill Kvalvaag - avatar
0
here is a sample how I did: URL myurl = new URL("http://example.com/article.html"); String text = ""; Scanner scanner = new Scanner (url.openStream ()); while (scanner.hasNextLine ()){ text += scanner.nextLine (); } scanner.close (); System.out.println (text)
17th May 2017, 6:04 AM
Daniel S
Daniel S - avatar