📄 readurl.java
字号:
import java.net.*;
import java.io.*;
class ReadURL
{
public static void main(String[] args)
{
try
{
// Define a URL
URL sourceURL = new URL("http://www.ncsa.uiuc.edu/demoweb/url-primer.html");
// Get a character input stream for the URL
BufferedReader in = new BufferedReader(
new InputStreamReader(
sourceURL.openStream()));
// Create the stream for the output file
PrintWriter out = new PrintWriter(
new BufferedWriter(
new FileWriter(
new File("C:\\JunkData\\netdata.html"))));
System.out.println("Reading the file " + sourceURL.getFile() +
" on the host " + sourceURL.getHost() +
" using " + sourceURL.getProtocol());
// Read the URL and write it to a file
String buffer; // Buffer to store lines
while(!(null==(buffer=in.readLine())))
out.println(buffer);
in.close(); // Close the input stream
out.close(); // Close the output file
}
catch(MalformedURLException e)
{
System.out.println("Failed to create URL:\n" + e);
}
catch(IOException e)
{
System.out.println("File error:\n" + e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -