L指定的页面以流的形式读出,写成指定的文件***/
try{
StringstrHtml="";
while((strHtml=stdIn.readLine())!=null){
stdOut.println(strHtml);
}
}
catch(IOExceptione){
throwe;
}
finally{
try{
if(stdIn!=null)
stdIn.close();
if(stdOut!=null)
stdOut.close();
}
catch(Exceptione){
System.out.println(e);
}
}
9。直接下载网上的文件
intbytesum=0;
intbyteread=0;
URLurl=newURL("http://pimg.163.com/sms/micheal/logo.gif");
URLConnectionconn=url.openConnection();
InputStreaminStream=conn.getInputStream();
FileOutputStreamfs=newFileOutputStream("c:/abc.gif");
byte[]buffer=newbyte[1444];
intlength;
while((byteread=inStream.read(buffer))!=-1)
{
out.println("
"+byteread+"");
bytesum+=byteread;
System.out.println(bytesum);
fs.write(buffer,0,byteread);
}
10。按行读文件
FileReadermyFileReader=newFileReader("c:/哈哈.txt");
BufferedReadermyBufferedReader=newBufferedReader(myFileReader);
StringmyString=null;
StringresultString=newString();
while((myString=myBufferedReader.readLine())!=null){resultString=resultString+myString+"
";}
out.println(resultString);myFileReader.close();