資源簡介
手機號歸屬地查詢,JAVA工具類,附帶SDK包,附帶源碼,附帶數據源,支持超大文本解析
代碼片段和文件信息
import?java.io.BufferedReader;
import?java.io.File;
import?java.io.FileInputStream;
import?java.io.InputStreamReader;
import?java.io.StringReader;
import?com.alibaba.fastjson.JSONReader;
/**
?*?手機號碼歸屬工具類
?*?
?*?@author?MYL
?*/
public?class?PhoneNumAddress?{
/**
?*?讀取文本JSON
?*?
?*?@param?filePath
?*?@return
?*/
public?static?String?readTxt(String?filePath)?{
StringBuilder?sb?=?new?StringBuilder();
try?{
File?file?=?new?File(filePath);
if?(file.isFile()?&&?file.exists())?{
InputStreamReader?isr?=?new?InputStreamReader(
new?FileInputStream(file)?“GBK“);
BufferedReader?br?=?new?BufferedReader(isr);
String?lineTxt?=?null;
while?((lineTxt?=?br.readLine())?!=?null)?{
sb.append(lineTxt);
}
br.close();
}?else?{
System.out.println(“文件不存在!“);
}
}?catch?(Exception?e)?{
System.out.println(“文件讀取錯誤!“);
}
return?sb.toString();
}
/**
?*?歸屬地查詢(利用FastJson解析檢索內容)
?*?
?*?@param?jsonString
?*?@param?str
?*/
@SuppressWarnings(“resource“)
public?static?void?fastParseJson(String?jsonString?String?str)?{
String?str2?=?““;
//?打印標識?0:關閉1啟動
int?startPrint?=?0;
JSONReader?reader?=?new?JSONReader(new?StringReader(jsonString));
//?讀取list數組
reader.startArray();
while?(reader.hasNext())?{
//?打印次數
int?countPrint?=?4;
//?讀取對象
reader.startobject();
while?(reader.hasNext())?{
//?把所有雙引號包含內容讀取成key?例:{“name“:“張三““sex“:“男“}?key={namesex}
String?arrayListItemKey?=?reader.readString();
//?獲取的key的鍵值?例:{“name“:“張三““sex“:“男“}?value={張三男}
String?arrayListItemValue?=?reader.readobject().toString();
if?(arrayListItemKey.equals(“CODE“))?{
if?(arrayListItemValue.equals(str.substring(0?7)))?{
//?啟動打印
startPrint?=?1;
}
}
//?打印拼接功能
if?(startPrint?==?1?&&?countPrint?>?0)?{
//?System.out.print(arrayListItemKey?+?“:“?+
//?arrayListItemValue?+?““);
str2?+=?“\““+arrayListItemKey?+?“\“:\““?+?arrayListItemValue?+?“\““;
//?減少打印次數
countPrint--;
}
//?停止打印程序結束
if?(countPrint?==?0)?{
//?System.out.println();
System.out.println(“{“+str2.substring(0?str2.length()?-?1)+“}“);
return;
}
}
reader.endobject();
}
reader.endArray();
System.out.println(“字典中不存在“);
}
/*
?*?超大文本解析工具類?需要?fastjson-1.2.51.jar
?*/
public?static?void?main(String[]?args)?{
String?a?=?“1709804“;
String?dic?=?readTxt(“D:\\Users\\Desktop/ss.dat“);
PhoneNumAddress.fastParseJson(dic?a?+?“1234“);
}
}
- 上一篇:Java飛機大戰源碼
- 下一篇:圖書管理系統Java開發源代碼+mysql數據庫
評論
共有 條評論