1.I am Saving the Android GPS enable and disable Time using a Text Log file inside SD card.
I want to Print multiple lines text, without erasing Previous Line data.
Below code is Printing Multiple lines Perfectly But When App is Kept in Sleep and Restarting . Printing a row along with Previous data Count, when GPS ON or OFF.
Help me how to fix it.
Required Output:(after Restart the app)
<< GPs Enabled At :2016/06/08 17.15.00>>
<< GPs Disabled At :2016/06/08 17.45.00>>
<< GPs Enabled At :2016/06/08 17.49.00>>
<< GPs Disabled At :2016/06/08 17.52.00>>
Getting Output:(after Restart the app)
<< GPs Enabled At :2016/06/08 17.15.00>>
<< GPs Disabled At :2016/06/08 17.45.00>>
<< GPs Enabled At :2016/06/08 17.49.00>>
<< GPs Disabled At :2016/06/08 17.52.00>>
<< GPs Disabled At :2016/06/08 17.52.00>>
<< GPs Disabled At :2016/06/08 17.52.00>>
method For Log File:
public void Logmethod(String NoramalStr,String Dateval)
{
/* Log FOlder Text files Starts here*/
try {
File newFolder = new File(Environment.getExternalStorageDirectory(), "GpsFolder");
if (!newFolder.exists()) {
newFolder.mkdir();
}
try {
File file = new File(newFolder, "GPSStatus" + ".txt");
file.createNewFile();
/*Writing the Log in specific files*/
BufferedWriter out;
try {
String separator1 = System.getProperty("line.separator");
FileOutputStream fOut = new FileOutputStream(new File(newFolder + "/GPSStatus.txt"), true);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.append("<< " + NoramalStr +" : "+Dateval + " >>");
osw.append(separator1); // this will add new line ;
osw.flush();
osw.close();
fOut.close();
Log.i(NoramalStr," : "+Dateval);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception ex) {
System.out.println("ex: " + ex);
}
} catch (Exception e) {
System.out.println("e: " + e);
}
}