Javaは、Webサーバーからファイルを読み込みます

package lianxi;
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class lianxi {
public static void main(String []args) {
Scanner input=null;
try {
	URL url=new URL("https://home.firefoxchina.cn/".trim());
	input=new Scanner(url.openStream());
	while(input.hasNext())
		System.out.println(input.nextLine());
} 
catch (MalformedURLException e) {
	// TODO 自动生成的 catch 块
	System.out.println("URL没发现");
}
catch (IOException e) {
	// TODO 自动生成的 catch 块
	e.printStackTrace();
}
finally {
	if(input!=null)
		input.close();
}
}
}

在这里插入代码片
公開された130元の記事 ウォン称賛16 ビュー30000 +

おすすめ

転載: blog.csdn.net/feiqipengcheng/article/details/104727264