public static void main(String[] args) throws IOException {
URL url = new URL("这里是网址");
URLConnection conn = url.openConnection();// 获得UrlConnection 连接对象
InputStream is = conn.getInputStream();// 获得输入流
BufferedReader br = new BufferedReader(new InputStreamReader(is));// buffered表示缓冲类
String str;
FileWriter fw = null;
while ((str = br.readLine()) != null) {
fw = new FileWriter("D:\\1.txt");
System.out.println(str);
fw.write(str);
fw.flush();
}
fw.close();
}求大神们赐教
1 回答
已采纳
Caballarii
TA贡献1123条经验 获得超629个赞
你每次都开个新的FileWriter,当然是把前面的内容全覆盖了
把fw = new FileWriter("D:\\1.txt");移到循环外面先
添加回答
举报
0/150
提交
取消