import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
public class TestThread1 {
public static void main(String[] args) {
new Hello().start();;
new PageRead().start();
}
}
class Hello extends Thread{
public void run() {
for(int i=0;i<100;i++){
System.out.println("Hello, Java,I like you!");
}
}
}
class PageRead extends Thread{
public void run() {
try {
URL url = new URL("http://127.0.0.1:8080/myweb/daohang.html");
InputStream input = url.openStream();
//这里自己改一下要输出的文件路径
FileOutputStream out = new FileOutputStream(new File("mydaoh.html"));
byte[] buffer = new byte[1024];
while(input.read(buffer)!=-1){
out.write(buffer);
}
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
}