How to write data into a file in android

 * @param filePath path of file
 * @param fileData data which you want to insert into the above file
 * @return <b>true</b> if data was written to the file<br/>
 * <b>false</b> if data was not written to the file<br/><br/>
 * <b>Note:</b> This requires permission <b>"android.permission.WRITE_EXTERNAL_STORAGE"</b>
 * This will override the data which exists in the file
 public static boolean writeDataToFile(String filePath, String fileData)
 boolean success = false;

 if(filePath!=null && fileData!=null)
 filePath = filePath.trim();
 fileData = fileData.trim();

 if(!filePath.equals("") && !fileData.equals(""))
 File srcFile = new File(filePath);

 if(srcFile.exists() && srcFile.isFile())
 FileOutputStream stream = new FileOutputStream(filePath);
 OutputStreamWriter out = new OutputStreamWriter(stream);
 success = true;
 catch (Exception e)
 return success;


Tags: ,

About krishjlk

Leave a Reply

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

You are commenting using your 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: