To save images (modified from the codes found here). bitmap is saved into .JPEG image files with lossless compression.
// Save bitmap String extStorageDirectory = Environment.getExternalStorageDirectory().toString(); OutputStream outStream = null; File file = new File(extStorageDirectory, "/DCIM/bitmap"+fileNo+".JPEG"); try { outStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream); outStream.flush(); outStream.close(); } catch(Exception e) { }
To save text files (modified from function found here)
private void writeToFile(String content, final String filename) { try { File file = new File(Environment.getExternalStorageDirectory() + "/DCIM/" + filename); //File file = new File("/DCIM/test.txt"); Log.i(TAG, Environment.getExternalStorageDirectory() + "/DCIM/" + filename); if (!file.exists()) { file.createNewFile(); } FileWriter writer = new FileWriter(file); writer.append(content); writer.flush(); writer.close(); } catch (IOException e) { } }
No comments:
Post a Comment