-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadWebpage.java
More file actions
45 lines (37 loc) · 1.34 KB
/
DownloadWebpage.java
File metadata and controls
45 lines (37 loc) · 1.34 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.sample;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
public class DownloadWebpage {
public static void main(String args[]) throws IOException {
String url = "https://www.youtube.com/mycodeschool/";
DownloadPage(url);
}
public static void DownloadPage(String webpage)
{
try {
// Create URL object
URL url = new URL(webpage);
BufferedReader readr =
new BufferedReader(new InputStreamReader(url.openStream()));
// Enter filename in which you want to download
BufferedWriter writer =
new BufferedWriter(new FileWriter("C:/Users/prem/Download.html"));
// read each line from stream till end
String line;
while ((line = readr.readLine()) != null) {
writer.write(line);
}
readr.close();
writer.close();
System.out.println("Successfully Downloaded.");
}
// Exceptions
catch (MalformedURLException mue) {
System.out.println("Malformed URL Exception raised");
}
catch (IOException ie) {
System.out.println("IOException raised");
}
}
}