How to put the contents of a file to a String of array in java -
i have string array contains records ,now have put records in file , have read values , have check records string array values.here string array..
public final static string fields[] = { "fileid", "filename", "eventtype", "recordtype", "accesspointnameni", "apnselectionmode", "causeforrecclosing", "chchselectionmode", "chargingcharacteristics", "chargingid", "duration", "dynamicaddressflag", "ipbinv4addressggsn", "datavolumefbcdownlink", "datavolumefbcuplink", "qosinformationneg"};
i have put these records in map using these,,
static linkedhashmap<string, string> getmetadata1() { linkedhashmap<string, string> md = new linkedhashmap<>(); (string fieldname : fields) md.put(fieldname, ""); return md;
}
now file
fileid filename eventtype recordtype accesspointnameni apnselectionmode causeforrecclosing chchselectionmode chargingcharacteristics chargingid duration dynamicaddressflag ipbinv4addressggsn datavolumefbcdownlink datavolumefbcuplink qosinformationneg
now reading file function
static linkedhashmap<string, string> getmetadata() { linkedhashmap<string, string> md = new linkedhashmap<>(); bufferedreader br = null; try { string scurrentline; string file[]; br = new bufferedreader(new filereader("./file/huagprsconf")); while ((scurrentline = br.readline()) != null) { md.put(scurrentline, ""); } } catch (ioexception e) { e.printstacktrace(); } { try { if (br != null) br.close(); } catch (ioexception ex) { ex.printstacktrace(); } } return md; }
now 2 functions returing values in 2 different ways..the string giving
{fileid=, filename=, eventtype=, recordtype=, accesspointnameni=, apnselectionmode=, causeforrecclosing=, chchselectionmode=, chargingcharacteristics=, chargingid=, duration=, dynamicaddressflag=, ipbinv4addressggsn=, datavolumefbcdownlink=, datavolumefbcuplink=, qosinformationneg=}
but file 1 getting values giving values big spaces..
{ fileid =, filename=, eventtype=, recordtype=, accesspointnameni=, apnselectionmode=, causeforrecclosing=, chchselectionmode=, chargingcharacteristics=, chargingid=, duration=, dynamicaddressflag=, ipbinv4addressggsn=, datavolumefbcdownlink=, datavolumefbcuplink=, qosinformationneg=, rattype=, ratinggroup=, resultcode=, serviceconditionchange=, ipbinv4address=, sgsnplmnidentifier=, timeoffirstusage=, timeoflastusage=, timeofreport=, timeusage=, changecondition=, changetime=,.... on
now when trying check 2 values using function not equal..
linkedhashmap<string, string> md1=getmetadata(); linkedhashmap<string, string> md2=getmetadata1(); if(md1.equals(md2)){ system.out.println(md1); }else{ system.out.println("not"); }
i cannot understand problem can help...
you should use scurrentline.trim()
remove unnnecessary whitespace.
Comments
Post a Comment