Hi,
I am writing to file in android and read from the same file using the below code:
//Write data on file
FileOutputStream fOut = null;
OutputStreamWriter osw = null;
try {
fOut = openFileOutput("gasettings.dat", MODE_PRIVATE);
osw = new OutputStreamWriter(fOut);
osw.write(data);
osw.flush();
Toast.makeText(context, "Settings saved", Toast.LENGTH_SHORT)
.show();
}
catch (Exception e) {
e.printStackTrace();
}
and the code for reading from file is:
InputStreamReader isr = null;
fileInputStream fIn = null;
char[] inputBuffer = new char[255];
String data = null;
try {
fIn = openFileInput("gasettings.dat");
isr = new InputStreamReader(fIn);
isr.read(inputBuffer);
data = new String(inputBuffer);
}
catch (Exception e) {
e.printStackTrace();
}
as per now I am only able to save a string to this file. I like to write a DATE array to it and also want to read back the data as array. I know that the return type of read method will be changed, but I am not getting the idea of how to read and write the DATE array or any other array to the file.
Thanks