/*
First of you need to add the proper permissions to the manifest

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Then call prepareSdCard from for instance onCreate to make sure that the SD card is mounted and that 
your directories are present.

*/

	/**
	 * Returns the path where you want to store your files
	 * @return
	 */
	private String getSavePath(){
		return String.format(Environment
				.getExternalStorageDirectory()
				+ "/YourAppOrOtherDirNameOfYourChoice/");
	}
	
	/**
	 * Prepares the SD card by creating our subfolder where we will store all
	 * our images in.
	 */
	private void prepareSdCard() {
		if (android.os.Environment.getExternalStorageState().equals(
				android.os.Environment.MEDIA_MOUNTED)) {
			File sDir = new File(getSavePath());
			if (!sDir.exists()) {
				sDir.mkdirs();
			}
		} else {
			dlgInfo("There is no memory card available. This application requires a memory card to store the files on.");
		}
	}	

	/**
	 * Appends a text to the specified file
	 * 
	 * @param fileName
	 * 	         Path and name of the file to save to 
	 * @param txt
	 *           Text to append to the file 
	 */
	private void writeTextFile(String fileName, String txt){
		try {
			FileWriter writer = new FileWriter(new File(fileName));
			writer.append(txt);
			writer.flush();
			writer.close();		
		} catch (Exception e) {
			Toast.makeText(this, "Unable to save file " + fileName, Toast.LENGTH_LONG);
		}
	}