Most of the code on the Internet is outdated, so get ready to do it yourself. Get the data source
Http://ip.chinaz.com/getip.aspx
The effect is as follows:
The code is as follows:
public static string Getmyip () throws IOException {
string url= "http://ip.chinaz.com/getip.aspx";
InputStream is = new URL (URL). OpenStream ();
try {
BufferedReader rd = new BufferedReader (new InputStreamReader (IS, Charset.forname ("UTF-8"));
StringBuilder sb = new StringBuilder ();
int CP;
while (cp = Rd.read ())!=-1) {
sb.append ((char) CP);
String Jsontext = sb.tostring ();;
Jsontext=jsontext.replaceall ("'", "");
Jsontext=jsontext.substring (1,jsontext.length ()-1);
Jsontext=jsontext.replaceall (",", "<br/>");
return jsontext;
} finally {
is.close ();
System.out.println ("At the same time it can be seen from here that even if return, will still implement finally." ");
}