List of usage examples for android.content Context MODE_APPEND
int MODE_APPEND
To view the source code for android.content Context MODE_APPEND.
Click Source Link
From source file:Main.java
public static void writeFile(Context context, String text, String fileName) { try {//www . j a va 2 s.c om FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_APPEND); fos.write(text.getBytes()); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void putCityName(Context context, String cityName) { Editor editor = context.getSharedPreferences(FILE_NAME, Context.MODE_APPEND).edit(); editor.putString(CITY_INFO, cityName); editor.commit();//www . j a va 2 s . c om }
From source file:Main.java
public static void storeInteger(Context context, String key, int value) { SharedPreferences pre = context.getSharedPreferences(STORE_NAME, Context.MODE_APPEND); pre.edit().putInt(STORE_KEY_PREFIX + key, value).commit(); }
From source file:Main.java
public static String getHome(Context context) { addressPreferences = context.getSharedPreferences(ADDRESS_PREFERENCE, Context.MODE_APPEND); return addressPreferences.getString(HOME_ADDRESS, ""); }
From source file:Main.java
public static void intArrayToFile(Context myContext, String filename, int[] array) { File root = myContext.getFilesDir(); File current = new File(root, filename); current.delete();/*from w w w . java 2 s . co m*/ FileOutputStream outputStream; try { outputStream = myContext.openFileOutput(filename, Context.MODE_APPEND); for (int i : array) { String s = "" + i; outputStream.write(s.getBytes()); outputStream.write("\n".getBytes()); } outputStream.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void saveJsonToFile(String toSave, String filename, Activity currActivity) { // check if the file exists File dir = currActivity.getFilesDir(); File file = new File(dir, filename); if (file.exists()) { file.delete();/*from w w w . ja v a 2 s . co m*/ } FileOutputStream outputStream; try { outputStream = currActivity.openFileOutput(filename, Context.MODE_APPEND); outputStream.write(toSave.getBytes()); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
private static SharedPreferences getSharedPreferences(Context context) { return context.getSharedPreferences("NightModeDemo", Context.MODE_APPEND); }
From source file:Main.java
@SuppressWarnings("resource") public static void writeInfoTophone(Context context, InputStream scriptData, String filePath) throws IOException { String temp = null;/*from w ww .j av a 2s . c o m*/ Log.d("Tag", "Starting write file"); FileOutputStream fos = null; if (isSdcardAvailable()) { removeExistFile(filePath); fos = new FileOutputStream(filePath, true); } else { removeExistFile(filePath); fos = context.openFileOutput(filePath, Context.MODE_APPEND); } BufferedReader mBufferedReader = new BufferedReader(new InputStreamReader(scriptData)); while ((temp = mBufferedReader.readLine()) != null) { fos.write((temp + "\n").getBytes()); } fos.close(); }
From source file:reco.frame.tv.http.entityhandler.FileEntityHandler.java
public Object handleEntity(Context appContext, HttpEntity entity, EntityCallBack callback, String target, boolean isResume) throws IOException { if (TextUtils.isEmpty(target) || target.trim().length() == 0) return null; File targetFile = new File(target); if (!targetFile.exists()) { targetFile.createNewFile();//from ww w . ja v a 2 s .co m } if (mStop) { return targetFile; } long current = 0; FileOutputStream os = null; if (isResume) { current = targetFile.length(); os = appContext.openFileOutput(target.substring(target.lastIndexOf("/") + 1), Context.MODE_APPEND | Context.MODE_WORLD_READABLE); //os = new FileOutputStream(target, true); } else { os = appContext.openFileOutput(target.substring(target.lastIndexOf("/") + 1), Context.MODE_WORLD_READABLE); } if (mStop) { return targetFile; } InputStream input = entity.getContent(); long count = entity.getContentLength() + current; if (current >= count || mStop) { return targetFile; } int readLen = 0; byte[] buffer = new byte[1024]; while (!mStop && !(current >= count) && ((readLen = input.read(buffer, 0, 1024)) > 0)) {// os.write(buffer, 0, readLen); current += readLen; callback.callBack(count, current, false); } callback.callBack(count, current, true); if (mStop && current < count) { // throw new IOException("user stop download thread"); } return targetFile; }
From source file:com.folio3.parse.MainActivity.java
public static void writeLogToFile(Context context, String alert) { String eol = System.getProperty("line.separator"); BufferedWriter writer = null; try {//from ww w . ja v a 2 s . c o m FileOutputStream openFileOutput = context.openFileOutput(FILE, Context.MODE_APPEND); openFileOutput.write((alert + "\r\n").getBytes()); } catch (Exception e) { throw new RuntimeException(e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } }