-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoader.java
More file actions
27 lines (23 loc) · 882 Bytes
/
Loader.java
File metadata and controls
27 lines (23 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Scanner;
import java.net.*;
public class Loader {
/**
* This method receives a URL, performs a connection and loads its content into a Scanner. Returns the content loaded.
* @param URLInput string that contains a URL link to the HTML structure to be loaded.
* @return the content loaded by connecting and scanning from URLInput.
*/
public String getContent (String URLInput) {
String content = null;
URLConnection connection = null;
try {
connection = new URL(URLInput).openConnection();
Scanner scanner = new Scanner(connection.getInputStream());
scanner.useDelimiter("\\Z");
content = scanner.next();
scanner.close();
} catch ( Exception ex ) {
return null;
}
return content;
}
}