Android : Reading a huge file efficiently

on Saturday, April 18, 2015


I am downloading a huge file from server,which is containing latitudes and longitudes in the form:



lat long


It is containing at least 2000 (lat,long).Now I want to read this file line wise and find out some lats and longs atleast 1 KM away,for finding distance I have already done and I also did for reading file using scanner class but at the end of some files there are blank lines which are creating problem ,I think. Code:



private List<LatLng> setLatLangs(File latlangs)
throws FileNotFoundException {
List<LatLng> mylist;
mylist = new ArrayList<LatLng>();
Scanner sc = new Scanner(latlangs);

while (sc.hasNextDouble()) {
for (int j = 0; j < 2; j++) {

double lat = sc.nextDouble();
double lang = sc.nextDouble();

LatLng w = new LatLng(lat, lang);
mylist.add(w);
}

}

return mylist;
}


This code is I have written but it is not working with huge files which are having some dummy lines at the end or any other problem. Please suggest me some efficient way to do it which works in every case. Tried to findout in logcat it is giving windowleaked error.


0 comments:

Post a Comment