Hallo Leute ich möchte gerne eine Txtdatei, die ich im Internet habe auslesen und als String im JLabel ausgeben lassen. Hab schon mal was gesucht aber nicht wirklich was gutes gefunden. Ich hoffe mir kann einer helfen
/**
* Downloads webpages from the interwebs and returns the String value.
*
* @param url
* @return
*/
public String getPage(URL url) {
String content = null;
int MAX_PAGE_SIZE = 1000000;
try {
// try opening the URL
URLConnection urlConnection = url.openConnection();
urlConnection.setAllowUserInteraction(false);
InputStream urlStream = url.openStream();
byte buffer[] = new byte[1000];
int numRead = urlStream.read(buffer);
content = new String(buffer, 0, numRead);
while ((numRead != -1) && (content.length() < MAX_PAGE_SIZE)) {
numRead = urlStream.read(buffer);
if (numRead != -1) {
String newContent = new String(buffer, 0, numRead);
content += newContent;
}
}
} catch (IOException | IndexOutOfBoundsException ex) {
appendLog("ERROR: Error while downloading from external source!");
appendLog(ex.toString());
return null;
}
return content;
}
void showText() {
getPage(new URL("http://team-m4gkbeatz.eu/index.php"));
}