package jdk7;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class BufferInputStream {
public static void main(String[] args) throws Throwable {
//方法一
// File file = new File("d:\\jsgz\\jsgz.html");
// OutputStream out = new FileOutputStream(file);
//
// URL url=new URL("http://www.baidu.com");
// HttpURLConnection httpUrl=(HttpURLConnection) url.openConnection();
// InputStream in = httpUrl.getInputStream();
// byte [] b =new byte[1024];
// int len=-1;
// while((len=in.read(b))!=-1){
// out.write(b, 0, len);
// }
// in.close();
// out.close();
//方法二
File file = new File("d:\\jsgz\\jsgz.html");
OutputStream out = new FileOutputStream("d:\\jsgz\\jsgz_new.html");
InputStream in = new FileInputStream(file);
byte [] b = new byte[(int)file.length()];
in.read(b);
out.write(b);
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class BufferInputStream {
public static void main(String[] args) throws Throwable {
//方法一
// File file = new File("d:\\jsgz\\jsgz.html");
// OutputStream out = new FileOutputStream(file);
//
// URL url=new URL("http://www.baidu.com");
// HttpURLConnection httpUrl=(HttpURLConnection) url.openConnection();
// InputStream in = httpUrl.getInputStream();
// byte [] b =new byte[1024];
// int len=-1;
// while((len=in.read(b))!=-1){
// out.write(b, 0, len);
// }
// in.close();
// out.close();
//方法二
File file = new File("d:\\jsgz\\jsgz.html");
OutputStream out = new FileOutputStream("d:\\jsgz\\jsgz_new.html");
InputStream in = new FileInputStream(file);
byte [] b = new byte[(int)file.length()];
in.read(b);
out.write(b);
}
}
先执行方法一,产生文件,在执行方法二。