Añadido boton de guardado y comienzo de interfaz de guardado en archivo físico
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package com.journaldev.gpslocationtracking;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class FIleManager {
|
||||
|
||||
|
||||
public void writeToFile(String data, Context context) {
|
||||
try {
|
||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("coordenadas.txt", Context.MODE_PRIVATE));
|
||||
outputStreamWriter.write(data);
|
||||
outputStreamWriter.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
Log.e("Exception", "File write failed: " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private String readFromFile(Context context) {
|
||||
|
||||
String ret = "";
|
||||
|
||||
try {
|
||||
InputStream inputStream = context.openFileInput("coordenadas.txt");
|
||||
|
||||
if ( inputStream != null ) {
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
|
||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||
String receiveString = "";
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
while ( (receiveString = bufferedReader.readLine()) != null ) {
|
||||
stringBuilder.append("\n").append(receiveString);
|
||||
}
|
||||
|
||||
inputStream.close();
|
||||
ret = stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
Log.e("login activity", "File not found: " + e.toString());
|
||||
} catch (IOException e) {
|
||||
Log.e("login activity", "Can not read file: " + e.toString());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user