Thingse/app/src/main/java/com/daneshzaki/thingse/Preferences.java
/*
	 * This method writes contents to a file
	 * */
This method writes contents to a file
This method writes contents to a file
private void writeContentToFile(String content, String fileName)
	{
		File exportFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + fileName);
		exportFileLocation = exportFile.getAbsolutePath();
		if (!exportFile.exists())
		{
			try
			{
				exportFile.createNewFile();
				Log.i("Preferences", "file created with name - " + exportFileLocation);
			} catch (IOException e)
			{
				Log.e("Preferences", "***unable to create file  " + e.getMessage(), e);
				e.printStackTrace();
			}
		}
		Log.i("Preferences", "file exists with name - " + exportFileLocation);
		try
		{
			BufferedWriter buf = new BufferedWriter(new FileWriter(exportFile, false));
			buf.append(content);
			buf.close();
		} catch (IOException e)
		{
			Log.e("Preferences", e.getMessage(), e);
			e.printStackTrace();
		}
	}
private void writeContentToFile ( String content , String fileName ) { File exportFile = new File ( Environment . getExternalStorageDirectory ( ) . getAbsolutePath ( ) + File . separator + fileName ) ; exportFileLocation = exportFile . getAbsolutePath ( ) ; if ( ! exportFile . exists ( ) ) { try { exportFile . createNewFile ( ) ; Log . i ( "Preferences" , "file created with name - " + exportFileLocation ) ; } catch ( IOException e ) { Log . e ( "Preferences" , "***unable to create file  " + e . getMessage ( ) , e ) ; e . printStackTrace ( ) ; } } Log . i ( "Preferences" , "file exists with name - " + exportFileLocation ) ; try { BufferedWriter buf = new BufferedWriter ( new FileWriter ( exportFile , false ) ) ; buf . append ( content ) ; buf . close ( ) ; } catch ( IOException e ) { Log . e ( "Preferences" , e . getMessage ( ) , e ) ; e . printStackTrace ( ) ; } }
This method writes contents to a file
This method writes contents to a file
// create a file if it does not exist // check if file exists // write to the file // BufferedWriter for performance, true to set append to file flag