I am writing a file in android and reading from the same file using the code below:
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 code to read from a file:
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 of now, I can only save the line in this file. I like to write a DATE array, and also read data as an array. I know that the return type of the read method will be changed, but I donβt understand how to read and write a DATE array or any other array to a file.
thank
source
share