InputStreamReader | InputStreamWriter
package IOTest_7;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
/**
* 获取网页源码
* @author Root
*InputStreamReader():从字节流到字符流的桥,它读取字节,并解码为指定的字符
*OutputStreamWriter():字符的桥梁流以字节流:向其写入的字符编码成使用指定的字节
*/
public class Test_1 {
public static void main(String[] args) {
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = new BufferedReader(new InputStreamReader(new URL("https://www.yanghuisen.cn").openStream(),"UTF-8"));
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("a.html"),"UTF-8"));
String msg = null;
while((msg = br.readLine())!=null) {
bw.write(msg);
bw.newLine();
}
bw.flush();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}