import java.io.*; import java.net.URL; import javax.swing.JTextArea; public class Test { static BufferedReader reader; static JTextArea tPage; static URL url; static String wenben; public static void main(String[] args) { tPage = new JTextArea(); String url = "<a target=_blank href="http://www.baidu.com/" target="_blank" style="background-color: inherit; cursor: pointer; color: rgb(202, 0, 0); text-decoration: none;">http://www.baidu.com</a>"; //网站路径 wenben="F:\\baidu.txt"; //存储路径 readPage(url); } public static void readPage(String uu) { String line; try { url = new URL(uu); reader = new BufferedReader(new InputStreamReader(url.openStream())); while ((line = reader.readLine()) != null) { tPage.append(line + "\n"); } cunchu(); System.out.println("存储成功"); } catch (Exception ie) { tPage.setText("发生输入输出异常 "); } finally { try { if (reader != null) reader.close(); } catch (Exception e) { } } } public static void cunchu() { File f = new File(wenben); try { f.createNewFile(); FileWriter out = new FileWriter(f); out.write(tPage.getText()); out.flush(); // 清空管道 out.close(); } catch (IOException e) { e.printStackTrace(); } } }