任何人都可以帮助我使用 Java URL 阅读器吗?
我在 Java 中创建了一个 URL 阅读器,它读取链接并将其发送到特定文件。如何从两个 URL 读取代码并将其保存到特定文件中?
这是我的代码:
import java.net.*;
import java.io.*;
public class URLReader {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://www.oracle.com/");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
BufferedWriter psout = new BufferedWriter(new FileWriter("D:\\final.txt"));
while ((inputLine = in.readLine()) != null) {
psout.write(inputLine);
System.out.println(inputLine);
}
in.close();
psout.close();
}
}