/**
* @author orochi-100
* @version 07.04.2020
*/
public class Main {
public static void main(String[] args) {
System.out.println(new FileFetcher().fetchFileString("SiteSourceFetcher.java"));
}
}
import java.util.Scanner;
import java.net.URL;
import java.io.IOException;
/**
* @author orochi-100
* @version 07.04.2020
*/
public class SiteSourceFetcher {
public String fetchSiteString(String url) {
StringBuilder sourceCode = new StringBuilder();
try (Scanner scanner = new Scanner(new URL(urlString).openStream())) {
for (; scanner.hasNextLine(); sourceCode.append(scanner.nextLine()).append('\n'));
} catch (IOException e) {
e.printStackTrace();
}
return sourceCode.toString();
}
public String fetchSiteString(URL url) {
StringBuilder sourceCode = new StringBuilder();
try (Scanner scanner = new Scanner(url.openstream())) {
for (; scanner.hasNextLine(); sourceCode.append(scanner.nextLine()).append('\n'));
} catch (IOException e) {
e.printStackTrace();
}
return sourceCode.ToString();
}
}
import java.util.Scanner;
import java.io.FileReader;
import java.io.IOException;
/**
* @author orochi-100
* @version 07.04.2020
*/
public class FileFetcher {
public String fetchFileString(String fileName) {
StringBuilder sourceCode = new StringBuilder();
try (Scanner scanner = new Scanner(new FileReader(fileName))) {
for (; scanner.hasNextLine(); sourceCode.append(scanner.nextLine()).append('\n'));
} catch (IOException e) {
e.printStackTrace();
}
return sourceCode.toString();
}
}