import java.io.*;
import java.net.URL;
import java.net.URLConnection;
public class downloadit {
/**
* @param args
*/
public static void main(String[] args) {
// // TODO Auto-generated method stub
// URL url = new URL("http://pagead2.googlesyndication.com/pagead/show_ads.js");
// BufferedReader br = new BufferedReader(new InputStream(url));
//// new BufferReader (new InputStremReader());
OutputStream out;
URLConnection conn;
InputStream in;
try {
String address = "http://pagead2.googlesyndication.com/pagead/show_ads.js";
String localFileName = "downloaed";
URL url = new URL(address);
out = new BufferedOutputStream(
new FileOutputStream(localFileName));
conn = url.openConnection();
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
numWritten += numRead;
}
System.out.println(localFileName + "\t" + numWritten);
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
import java.net.URL;
import java.net.URLConnection;
public class downloadit {
/**
* @param args
*/
public static void main(String[] args) {
// // TODO Auto-generated method stub
// URL url = new URL("http://pagead2.googlesyndication.com/pagead/show_ads.js");
// BufferedReader br = new BufferedReader(new InputStream(url));
//// new BufferReader (new InputStremReader());
OutputStream out;
URLConnection conn;
InputStream in;
try {
String address = "http://pagead2.googlesyndication.com/pagead/show_ads.js";
String localFileName = "downloaed";
URL url = new URL(address);
out = new BufferedOutputStream(
new FileOutputStream(localFileName));
conn = url.openConnection();
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
numWritten += numRead;
}
System.out.println(localFileName + "\t" + numWritten);
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
No comments:
Post a Comment