File file =new File("d:/xiyao");
listTxt(file);
public void listTxt(File file){
File files[]=file.listFiles();
String s =file.getName();
String s1="txt";
if(file.isFile()&&s.endsWith(s1)){
try{
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr=new InputStreamReader(fis);
BufferedReader tr=new BufferedReader(isr);
StringBuffer sb=new StringBuffer();
String line;
while((line=tr.readLine())!=null){
sb.append(line);
}
tr.close();
isr.close();
fis.close();
String jsonString=sb.toString();
JSONObject jsonObject=JSONObject.fromObject(jsonString);//把string转换为json对象
JSONObject body=jsonObject.getJSONObejct("body");//获取jsonObject中的body json对象
JSONArray data =body.getJSONArray("content");//获取json对象中的json数组
List<DrugsDataBase> drugsDataBases = new ArrayList<DrugsDataBase>();
//遍历json数组
for(int index = 0, length = data.size(); index < length; index++) {
DrugsDataBase drugsDataBase=new DrugsDataBase();
JSONObject ddb=data.getJSONObject(index); //获取数组中的每一个对象
drugsDataBase.setMedicalName(ddb.getString("commonName"));
drugsDataBase.setFactoryName(ddb.getString("factory"));
drugsDataBase.setMedicineBarCode(ddb.getString("commodityCode"));
drugsDataBase.setJiliang(ddb.getInt("dose"));//
}
}catch(IOException e){
e.printStackTrace();
}
}
if(file.isDirectory()){
for(File fileItem:files)
listTxt(fileItem);
}
}
json数据
{
"header": {
"currentTime": 1505805227492,
"clinicId": "ff80808157f9c4c6015803fdee73764b",
"v": "v_1.1411508",
"imei": "359175060431470",
"type": "2",
"doctorMainId": "ff80808157f9c4c6015803fec6a3764e"
},
"body": {
"synCode": "",
"code": "0000",
"param": {
"pageStart": "1",
"pageNum": "1000000",
"medicineShortName": "A"
},
"content": [
{
"commonName": "阿苯达唑胶囊1",
"factory": "云南龙润药业有限公司",
"commoditySpell": "ABDZJN1",
"quantum": "4",
"quantumUnit": "粒",
"specifcations": "0.1g",
"matrix": 10,
"dose": "0.4",
"medicinalNo": "11115413",
"commonUnit": "盒",
"rate": "一日1次",
"commodityCode": "6668767898989",
"id": "1178146",
"minUnit": "粒",
"medicinalFormId": "40288c2a5157239d015157365d6c0003",
"frequentness": "1",
"medicinalCategory": "1",
"commodityName": "阿苯达唑胶囊1",
"direction": "口服",
"frequentnessUnit": "日",
"doseUnit": "g"
},
{
"commonName": "阿苯达唑胶囊",
"factory": "武汉东信医药科技有限责任公司",
"commoditySpell": "ABDZJN",
"quantum": "4",
"quantumUnit": "粒",
"specifcations": "0.1g",
"matrix": 10,
"dose": "0.4",
"medicinalNo": "11083168",
"commonUnit": "盒",
"rate": "一日1次",
"commodityCode": "6951769100378",
"id": "1178147",
"minUnit": "粒",
"medicinalFormId": "40288c2a5157239d015157365d6c0003",
"frequentness": "1",
"medicinalCategory": "1",
"commodityName": "阿苯达唑胶囊",
"direction": "口服",
"frequentnessUnit": "日",
"doseUnit": "g"
},
{
"commonName": "阿苯达唑胶囊",
"factory": "福州海王福药制药有限公司",
"commoditySpell": "ABDZJN",
"quantum": "4",
"quantumUnit": "粒",
"specifcations": "0.1g",
"matrix": 10,
"dose": "0.4",
"medicinalNo": "11053902",
"commonUnit": "盒",
"rate": "一日1次",
"commodityCode": "6922943800520",
"id": "1178148",
"minUnit": "粒",
"medicinalFormId": "40288c2a5157239d015157365d6c0003",
"frequentness": "1",
"medicinalCategory": "1",
"commodityName": "阿苯达唑胶囊",
"direction": "口服",
"frequentnessUnit": "日",
"doseUnit": "g"
},
{
"commonName": "阿苯达唑胶囊",
"factory": "辅仁药业集团有限公司",
"commoditySpell": "ABDZJN",
"quantum": "4",
"quantumUnit": "粒",
"specifcations": "0.1g",
"matrix": 10,
"dose": "0.4",
"medicinalNo": "11107114",
"commonUnit": "盒",
"rate": "一日1次",
"commodityCode": "6922072560418",
"id": "1178149",
"minUnit": "粒",
"medicinalFormId": "40288c2a5157239d015157365d6c0003",
"frequentness": "1",
"medicinalCategory": "1",
"commodityName": "阿苯达唑胶囊",
"direction": "口服",
"frequentnessUnit": "日",
"doseUnit": "g"
},
{
"commonName": "阿苯达唑胶囊",
"factory": "通化仁民药业股份有限公司",
"commoditySpell": "ABDZJN",
"quantum": "4",
"quantumUnit": "粒",
"specifcations": "0.1g",
"matrix": 10,
"dose": "0.4",
"medicinalNo": "11126493",
"commonUnit": "盒",
"rate": "一日1次",
"commodityCode": "6925489320811",
"id": "1178150",
"minUnit": "粒",
"medicinalFormId": "40288c2a5157239d015157365d6c0003",
"frequentness": "1",
"medicinalCategory": "1",
"commodityName": "阿苯达唑胶囊",
"direction": "口服",
"frequentnessUnit": "日",
"doseUnit": "g"
},
{
"commonName": "阿苯达唑片",
"factory": "0",
"commoditySpell": "ABDZP",
"quantum": "1",
"quantumUnit": "片",
"specifcations": "0.2g",
"matrix": 10,
"dose": "0.2",
"medicinalNo": "11125398",
"commonUnit": "盒",
"rate": "一日1次",
"commodityCode": "6952489800395",
"id": "1178151",
"minUnit": "片",
"medicinalFormId": "d8c61da47f8d11e5b31128936a597f70",
"frequentness": "1",
"medicinalCategory": "1",
"commodityName": "阿苯达唑片",
"direction": "口服",
"frequentnessUnit": "日",
"doseUnit": "g"
},
{
"commonName": "阿苯达唑片",
"factory": "上海衡山药业有限公司",
"commoditySpell": "ABDZP",
"quantum": "1",
"quantumUnit": "片",
"specifcations": "0.2g",
"matrix": 10,
"dose": "0.2",
"medicinalNo": "11057769",
"commonUnit": "盒",
"rate": "一日1次",
"commodityCode": "6927091100492",
"id": "1178152",
"minUnit": "片",
"medicinalFormId": "d8c61da47f8d11e5b31128936a597f70",
"frequentness": "1",
"medicinalCategory": "1",
"commodityName": "阿苯达唑片",
"direction": "口服",
"frequentnessUnit": "日",
"doseUnit": "g"
},
{
"commonName": "阿胶当归口服液",
"factory": "四川泰华堂制药有限公司",
"commoditySpell": "AJDGKFY",
"quantum": "15",
"quantumUnit": "ml",
"specifcations": "150ml",
"matrix": 1,
"dose": "15",
"medicinalNo": "11101242",
"commonUnit": "盒",
"rate": "一日3次",
"commodityCode": "6906024009446",
"id": "1178246",
"minUnit": "瓶",
"medicinalFormId": "40288c2a5157239d0151574603040006",
"frequentness": "3",
"medicinalCategory": "2",
"commodityName": "阿胶当归口服液",
"direction": "口服",
"frequentnessUnit": "日",
"doseUnit": "ml"
}
]
}
}
网友评论