by ranjandeo » Sat Jul 10, 2010 6:24 am
Hi,
This is how you can write into a file and read from a file.
Different methods given below illustrate this...
public void writeIntoFile(){
FileOutputStream fOut = null;
OutputStreamWriter osw = null;
try{
fOut = openFileOutput("file.txt", Context.MODE_PRIVATE);
osw = new OutputStreamWriter(fOut);
osw.write("Write these text into file");
osw.close();
fOut.close();
}catch(Exception e){
e.printStackTrace(System.err);
}
}
public void readFromFile(){
FileInputStream fIn = null;
InputStreamReader isr = null;
try{
char[] inputBuffer = new char[1024];
String data = null;
fIn = openFileInput("file.txt");
isr = new InputStreamReader(fIn);
isr.read(inputBuffer);
data = new String(inputBuffer);
isr.close();
fIn.close();
}catch(IOException e){
e.printStackTrace(System.err);
}
}
Ranjan Deo