How to append data to a file in android

 * @param filePath path of file
 * @param fileDataToAppend data which you want to append into the above file
 * @return <b>true</b> if data was appended to the file<br/>
 * <b>false</b> if data was not appended to the file<br/><br/>
 * <b>Note:</b> This requires permission <b>"android.permission.WRITE_EXTERNAL_STORAGE"</b>
 public static boolean appendFile(String filePath, String fileDataToAppend)
 boolean success = false;

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

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

 if(srcFile.exists() && srcFile.isFile())
 FileWriter out = new FileWriter(filePath,true);
 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 )

Google photo

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

Connecting to %s

%d bloggers like this: