private void saveWikiData(IBeacon iBeacon, Location location) { FileOutputStream outputStream = null; String string = iBeacon.getProximityUuid() + "," + iBeacon.getMajor() + "," + iBeacon.getMinor() + "," + location.getLatitude() + "," + location.getLongitude() + "," + location.getAccuracy() + "," + location.getTime() + "\n"; try { File path = Environment.getExternalStoragePublicDirectory("wikiBeacon"); File file = new File(path, "log.csv"); boolean result = path.mkdirs(); if (IBeaconManager.LOG_DEBUG) Log.d("WikiBeaconDataReporter", "mkdirs on " + path + " returned " + result); outputStream = new FileOutputStream(file, true); outputStream.write(string.getBytes()); outputStream.close(); } catch (Exception e) { Log.e("WikiBeaconDataReporter", "can't write wikibeacon data to file ", e); } finally { try { if (outputStream != null) outputStream.close(); } catch (Exception e) { } } if (IBeaconManager.LOG_DEBUG) Log.d("WikiBeaconDataReporter", "Wrote data to " + this.context.getFilesDir()); }