File handeling in android

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

File handeling in android

Postby vani.golakoti » Sat Jun 26, 2010 10:03 am

Hi all,

If i insert a file(like a text file) in sdcard and i want to read and edit the file on the device(emulator), how can i achieve that.

Regards,
bhavani.G
vani.golakoti
Freshman
Freshman
 
Posts: 4
Joined: Wed May 19, 2010 7:18 pm

Top

Re: File handeling in android

Postby 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
User avatar
ranjandeo
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Mon May 31, 2010 6:20 am
Location: Kolkata, India

Top

Return to General

Who is online

Users browsing this forum: No registered users and 4 guests