RSS

Code to Create and Delete a file from sdcard in Android

15 Aug

* Code to create a file on sdcard :

private void createFile()
{
File file = new File(“sdcard/nikhil.html”);
if(!file.exists())
{
try
{
file.createNewFile();
BufferedWriter objBufferWriter = new BufferedWriter(new FileWriter(“sdcard/nikhil.html”));
objBufferWriter.write(strMessageBody);
objBufferWriter.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
else
{
Toast.makeText(getApplicationContext(), “File already exists”, Toast.LENGTH_SHORT).show();
}
}

* Code to Delete a file from sdcard :

private void deleteFile()
{
File file = new File(“sdcard/nikhil.html”);
if(file.exists())
{
file.delete();
}
}

Advertisements
 
Leave a comment

Posted by on August 15, 2011 in Android Source Code

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: