关于I/O的问题!
代码如下:
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实现呢??