Internal/External (Android)

//Storeing to asset/raw folder: not possible, you cannot modify your resources or assets after compile time. Store the file to the sdcard //Create a new folder in SD Card //First check if the sd card is mounted or not if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { // sd card mounted Log.d("SDCard", "SDcard is present"); } String folderName = "Images/"; //depend on you. File folder = new File(Environment.getExternalStorageDirectory() + File.separator + folderName"); String dicRectoryPath = folder.getAbsolutePath(); if(!folder.exists()) { folder.mkdirs(); //Creates the directory named by this abstract pathname Log.d("SDcard", "Folder created"); } else { Log.d("SDCard", "Folder already exists"); } String content = "hello world"; FileOutputStream outputStream; try { outputStream = new FileOutputStream(dicRectoryPath + "nameofyourfile"); outputStream.write(content.getBytes()); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } //Note /* You can try Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) instead of Environment.getExternalStorageDirectory() to save the file in the Downloads directory of your external storage. - getExternalStoragePublicDirectory(String type) requires one of these strings: DIRECTORY_MUSIC, DIRECTORY_PODCASTS, DIRECTORY_RINGTONES, DIRECTORY_ALARMS, DIRECTORY_NOTIFICATIONS, DIRECTORY_PICTURES, DIRECTORY_MOVIES, DIRECTORY_DOWNLOADS, or DIRECTORY_DCIM. May not be null. */ //You should try to use "ShowDialog" to let users know when the process finished.
This snippet shows how to store in internal and external

Don't forget to show me your own way to solve this issue.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.