-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageReader.java
More file actions
35 lines (28 loc) · 898 Bytes
/
PageReader.java
File metadata and controls
35 lines (28 loc) · 898 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
28
29
30
31
32
33
34
35
package Networking;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class PageReader {
public static void main(String[] args) throws IOException {
StringBuffer sb = new StringBuffer();
int singleChar = 0;
URL url = new URL("http://techstory.in/wp-content/uploads/2015/02/sachin-tendulkar-sifr-651867782.jpg");
URLConnection con = url.openConnection();
con.connect();
InputStream is = con.getInputStream();
FileOutputStream fo = new FileOutputStream("C:\\Users\\arnav\\Desktop\\HTML\\img.jpg");
singleChar = is.read();
while (singleChar != -1) {
fo.write(singleChar);
// sb.append((char)singleChar);
singleChar = is.read();
}
is.close();
// fo.write(sb.toString().getBytes());
fo.close();
System.out.println("Done...");
// System.out.println(sb);
}
}