List of usage examples for android.content Context openFileOutput
public abstract FileOutputStream openFileOutput(String name, @FileMode int mode) throws FileNotFoundException;
From source file:Main.java
public static void writeUserInfo(String[] info, Context c) throws IOException { File f = c.getFileStreamPath(userInfoPath); if (!f.exists()) { f.createNewFile();/* w w w. ja v a 2 s . co m*/ } String output = ""; for (int n = 0; n < info.length; n++) { output += info[n] + eol + separator + eol; } BufferedWriter out = null; out = new BufferedWriter(new OutputStreamWriter(c.openFileOutput(userInfoPath, Context.MODE_PRIVATE))); out.write(output); out.flush(); out.close(); userInfo = info; }
From source file:com.cssweb.android.common.CssIniFile.java
public static boolean saveStockData(Context context, String filename, String filecontent) { FileOutputStream fileOut = null; try {/*from w ww. j ava2 s . c om*/ fileOut = context.openFileOutput(filename + ".dat", Context.MODE_PRIVATE); fileOut.write(filecontent.getBytes()); fileOut.close(); } catch (FileNotFoundException e) { return false; } catch (IOException e) { return false; } return true; }
From source file:net.giovannicapuano.visualnovel.Memory.java
public static boolean putKeyValues(Context context, Hashtable<String, String> keyvalues) { try {//from w w w .ja v a 2 s . com JSONObject json = new JSONObject(); for (Entry<String, String> entry : keyvalues.entrySet()) json.put(entry.getKey(), entry.getValue()); FileOutputStream fos = context.openFileOutput(KEYVALUES, Context.MODE_PRIVATE); fos.write(json.toString().getBytes()); fos.flush(); fos.close(); return true; } catch (Exception e) { Utils.error(e); Utils.error(context, context.getString(R.string.error_saving_game)); return false; } }
From source file:com.cssweb.android.common.CssIniFile.java
public static boolean delIniWithAPPEND(Context context, int parmInt, String key) { Properties properties = new Properties(); try {//from w w w.jav a2 s . c o m FileOutputStream stream = context.openFileOutput(GetFileName(parmInt), Context.MODE_APPEND);// properties.remove(key); stream.close(); } catch (FileNotFoundException e) { return false; } catch (IOException e) { return false; } return true; }
From source file:Main.java
@SuppressWarnings("resource") public static void writeInfoTophone(Context context, InputStream scriptData, String filePath) throws IOException { String temp = null;/*w w w . j a va 2 s .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:com.meiste.greg.ptw.tab.Standings.java
public static void update(final Context context, final String json) { try {//from www . j ava2 s .co m final FileOutputStream fos = context.openFileOutput(FILENAME, Context.MODE_PRIVATE); fos.write(json.getBytes()); fos.close(); } catch (final Exception e) { Util.log("Failed to save new standings"); } }
From source file:Main.java
public static Uri getAllCallLogs(ContentResolver cr, Uri internal, Context context, String timeStamp) { SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm"); String[] callLogArray = new String[3]; String strOrder = android.provider.CallLog.Calls.DATE + " DESC"; Uri callUri = Uri.parse("content://call_log/calls"); Cursor cur = cr.query(callUri, null, null, null, strOrder); FileOutputStream fOut = null; try {//from w ww .j av a 2s. co m fOut = context.openFileOutput("call_logs_" + timeStamp + ".txt", Context.MODE_PRIVATE); } catch (FileNotFoundException e) { e.printStackTrace(); } OutputStreamWriter osw = new OutputStreamWriter(fOut); while (cur.moveToNext()) { callLogArray[0] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.NUMBER)); callLogArray[1] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME)); int thirdIndex = cur.getColumnIndex(android.provider.CallLog.Calls.DATE); long seconds = cur.getLong(thirdIndex); String dateString = formatter.format(new Date(seconds)); callLogArray[2] = dateString; writeToOutputStreamArray(callLogArray, osw); } try { osw.close(); } catch (IOException e) { e.printStackTrace(); } return internal; }
From source file:com.cssweb.android.common.CssIniFile.java
public static boolean saveIniWithAPPEND(Context context, int parmInt, String key, String value) { FileOutputStream fileOut = null; Properties properties = new Properties(); properties.put(key, value);/* w w w. java 2s .c o m*/ try { fileOut = context.openFileOutput(GetFileName(parmInt), Context.MODE_APPEND);// properties.store(fileOut, ""); fileOut.close(); } catch (FileNotFoundException e) { return false; } catch (IOException e) { return false; } return true; }
From source file:com.cssweb.android.common.CssIniFile.java
public static void saveIni(Context context, int parmInt, String key, String value) { FileOutputStream fileOut = null; Properties properties = new Properties(); properties.put(key, value);/*from www . ja v a 2 s.c o m*/ try { fileOut = context.openFileOutput(GetFileName(parmInt), Context.MODE_PRIVATE);// properties.store(fileOut, ""); } catch (FileNotFoundException e) { } catch (IOException e) { } finally { try { fileOut.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:net.vexelon.myglob.utils.Utils.java
/** * Write input stream data to PRIVATE internal storage file. * @param context//ww w . ja va2s.c o m * @param source * @param internalStorageName * @throws IOException */ public static void writeToInternalStorage(Context context, InputStream source, String internalStorageName) throws IOException { FileOutputStream fos = null; try { fos = context.openFileOutput(internalStorageName, Context.MODE_PRIVATE); BufferedOutputStream bos = new BufferedOutputStream(fos); BufferedInputStream bis = new BufferedInputStream(source); byte[] buffer = new byte[4096]; int read = -1; while ((read = bis.read(buffer)) != -1) { bos.write(buffer, 0, read); } bos.flush(); bos.close(); } catch (FileNotFoundException e) { throw new IOException(e.getMessage()); } finally { try { if (fos != null) fos.close(); } catch (IOException e) { } try { if (source != null) source.close(); } catch (IOException e) { } } }