p; String postalconf = fields.get(22); 58. String error = fields.get(23); 59. } 60. 61. in.close(); 62. } 63.} import java.net.MalformedURLException; import java.net.URL; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException;
public class OmniReader { public static void main(String[] args) throws Exception { String license_key = "YOUR_LICENSE_KEY"; String ip_address = "24.24.24.24";
String url_str = "http://geoip.maxmind.com/e?l=" + license_key + "&i=" + ip_address;
URL url = new URL(url_str); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String inLine; while ((inLine = in.readLine()) != null) { // Alternatively use a CSV parser here. Pattern p = Pattern.compile("\"([^\"]*)\"|(?<=,|^)([^,]*)(?:,|$)"); Matcher m = p.matcher(inLine);
ArrayList fields = new ArrayList(); String f; while (m.find()) { f = m.group(1); if (f!=null) { fields.add(f); } else { fields.add(m.group(2)); } } &nbs 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>
|