当读.jsp的网页时便会出现乱码,请各位高手帮帮忙。小弟在此谢过了。import java.net.*;
import java.io.*;public class URLResource
{
public static void main(String[] args)
{
try{ int n= -1;
byte b[]=new byte[118];
String s1=new String("http://222.180.184.22/PlanAndCurriculum/cour_tab_sel_stud.ASP");
URL url=new URL(s1);
InputStream in=url.openStream();
RandomAccessFile in_and_out=new RandomAccessFile(new File("schedule.txt"),"rw");
while((n=in.read(b))!= -1)
{
in_and_out.write(b,0,n);
}
in_and_out.close();
}
catch(MalformedURLException e){System.out.println("don't find this file"+e);}
catch(IOException el){System.out.println("io error"+el);}
}
}
import java.io.*;public class URLResource
{
public static void main(String[] args)
{
try{ int n= -1;
byte b[]=new byte[118];
String s1=new String("http://222.180.184.22/PlanAndCurriculum/cour_tab_sel_stud.ASP");
URL url=new URL(s1);
InputStream in=url.openStream();
RandomAccessFile in_and_out=new RandomAccessFile(new File("schedule.txt"),"rw");
while((n=in.read(b))!= -1)
{
in_and_out.write(b,0,n);
}
in_and_out.close();
}
catch(MalformedURLException e){System.out.println("don't find this file"+e);}
catch(IOException el){System.out.println("io error"+el);}
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
public class UrlCodeRegex_2
{
public static void main(String[] args)
{
try
{
String ur="http://222.180.184.22/PlanAndCurriculum/cour_tab_sel_stud.ASP";
URL MyURL=new URL(ur);
String str;
URLConnection con=MyURL.openConnection();
InputStreamReader ins=new InputStreamReader(con.getInputStream(),"gbk");
BufferedReader in=new BufferedReader(ins);
StringBuffer sb = new StringBuffer();
while ((str=in.readLine())!=null)
{
sb.append(str);
}
in.close();
System.out.println(sb.toString());
}
catch (IOException ioe) {
System.out.println("IOException: " + ioe);
}
}
}编码无非就是gbk,gb2312,utf-8,不行的话,你在我的代码里换换编码就是了
根据http协议,连接在不指定keep-alive时,是自动关闭的。呵呵!