Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // In case of HTTP 403
- System.setProperty("http.agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.29 Safari/537.36");
- URL url = new URL("url");
- InputStream stream = url.openStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(stream));
- StringBuilder sb = new StringBuilder();
- String line;
- while ((line = br.readLine()) != null) {
- sb.append(line);
- }
- stream.close();
- OR
- URL url = new URL("url");
- InputStream stream = url.openStream();
- BufferedInputStream bis = new BufferedInputStream(stream);
- StringBuilder sb = new StringBuilder();
- String line;
- while (true) {
- int data = bis.read();
- if (data == -1){
- break;
- } else {
- sb.append((char) data);
- }
- }
- bis.close();
- stream.close();
Add Comment
Please, Sign In to add comment