关于I/O的问题!

tomcatjava 2003-09-11 04:33:39
代码如下:
import java.io.*;
import java.net.*;
public class textwhile{
public static void main(String args[]) throws MalformedURLException,IOException{
String urlString,username,password;

System.getProperties().setProperty( "http.proxyHost", "202.119.24.35" );
System.getProperties().setProperty( "http.proxyPort", "8080" );

if(args.length!=3){
System.err.println("Usage: java AuthDemo URL username password");
System.exit(-1);
}
urlString=args[0];
username=args[1];
password=args[2];
Authenticator.setDefault(new MyAuthenticator(username,password));
URL url=new URL(urlString);
InputStream content=(InputStream)url.getContent();
BufferedReader in=new BufferedReader(new InputStreamReader(content));
String line;
StringBuffer lineBuf=new StringBuffer("");
//FileWriter out=new FileWriter(new File("F:\\URL.txt"));
BufferedWriter out=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("F:\\URL.txt"))));
while((line=in.readLine())!=null){
//System.out.println(line);//***
lineBuf.append(line+"\n");
}
out.write(lineBuf.toString());

System.out.println("Done.");
}//end main

static class MyAuthenticator extends Authenticator{
private String username,password;

public MyAuthenticator(String username,String password){
this.username=username;
this.password=password;
}

protected PasswordAuthentication getPasswordAuthentication(){
System.out.println("Requesting Host :"+getRequestingHost());
System.out.println("Requesting Port :"+getRequestingPort());
System.out.println("Requesting Prompt :"+getRequestingPrompt());
System.out.println("Requesting Protocol :"+getRequestingProtocol());
System.out.println("Requesting Scheme :"+getRequestingScheme());
System.out.println("Requesting Site :"+getRequestingSite());

return new PasswordAuthentication(username,password.toCharArray());
}
}//end MyAuthenticator
}//end testwhile
为什么URL.txt文件总是空的!!就是没写入!!!
如果加入//***那句,是可以在DOS窗口显示html文本的!!
该用什么I/O实现呢??
...全文
38 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fast_time 2003-09-11
  • 打赏
  • 举报
回复
UP
amjn 2003-09-11
  • 打赏
  • 举报
回复
out.flush();

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧