I don't exactly know how to explain this, but I'm trying to get 6 sentences from a webpage, to my java control panel thing. I've tried to use a snippet I found for twitter updates, and it works, except for the fact that I can't seperate them into new lines. this is what it looks like, Just an example..
i have cheese fries.I don't like cheese fries.I want cheese fries.Cheese fries are nasty.
so.. I tried to add the \n between each sentence but it doesn't do anything. so, I tried to add the html code <br />. this still didn't work.. How exactly do I get it to linebreak?
this is pretty much the void I used..
public void loadPages() {
String loadTextOnPage = null;
final StringBuilder url = new StringBuilder();
url.append("http://www.mypage.com/thispage.html");
InputStreamReader stream = null;
BufferedReader reader = null;
try {
stream = new InputStreamReader(new URL(url.toString()).openStream());
reader = new BufferedReader(stream);
String s;
int c = 0;
while ((s = reader.readLine()) != null) {
final String a = "<text>", b = "</text>";
int x = s.indexOf(a);
if (x == -1) {
continue;
}
x += a.length();
final int y = s.indexOf(b, x);
if (y == -1) {
continue;
}
String msg = s.substring(x, y).trim();
loadTextOnPage = msg;
}
} catch (final IOException ignored) {
} finally {
try {
if (reader != null) {
reader.close();
}
if (stream != null) {
stream.close();
}
} catch (final IOException ignored) {
}
}
}
I tried to make it load from an html file, and an xml file, and both had the same results.