How to get the internal and external sdcard path in android

How to get the internal and external sdcard path in android Methods to store in Internal Storage: File getDir (String name, int mode) File getFilesDir () Above methods are present in Context class Methods to store in phone’s internal memory: File getExternalStorageDirectory () File getExternalFilesDir (String type) File getExternalStoragePublicDirectory (String type) In the beginning, everyone … Read more

Android, how do can I get a list of all files in a folder?

To list all the names of your raw assets, which are basically the filenames with the extensions stripped off, you can do this: public void listRaw(){ Field[] fields=R.raw.class.getFields(); for(int count=0; count < fields.length; count++){ Log.i(“Raw Asset: “, fields[count].getName()); } } Since the actual files aren’t just sitting on the filesystem once they’re on the phone, … Read more

Difference between mkdir() and mkdirs() in java for java.io.File [closed]

mkdirs() also creates parent directories in the path this File represents. javadocs for mkdirs(): Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories. javadocs for mkdir(): Creates the directory named by … Read more

List all the files from all the folders in a single list

Try this: ….. List<File> files = getListFiles(new File(“YOUR ROOT”)); …. private List<File> getListFiles(File parentDir) { ArrayList<File> inFiles = new ArrayList<File>(); File[] files = parentDir.listFiles(); for (File file : files) { if (file.isDirectory()) { inFiles.addAll(getListFiles(file)); } else { if(file.getName().endsWith(“.csv”)) { inFiles.add(file); } } } return inFiles; } Or a variant without recursion: private List<File> getListFiles2(File parentDir) … Read more

Writing Text File to SD Card fails

You can use this method to check de sdCard state. Change the toast dialog to you language: ** Care with MEDIA_MOUNTED_READ_ONLY. In no need write in the SDCard and i return true ** public static Boolean comprobarSDCard(Context mContext) { String auxSDCardStatus = Environment.getExternalStorageState(); if (auxSDCardStatus.equals(Environment.MEDIA_MOUNTED)) return true; else if (auxSDCardStatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { Toast.makeText( mContext, “Warning, the … Read more

List all the files from all the folder in a single list

Try this: ….. List<File> files = getListFiles(new File(“YOUR ROOT”)); …. private List<File> getListFiles(File parentDir) { ArrayList<File> inFiles = new ArrayList<File>(); File[] files = parentDir.listFiles(); for (File file : files) { if (file.isDirectory()) { inFiles.addAll(getListFiles(file)); } else { if(file.getName().endsWith(“.csv”)){ inFiles.add(file); } } } return inFiles; } or variant without recursion: private List<File> getListFiles2(File parentDir) { List<File> … Read more

Trying to create a file in Android: open failed: EROFS (Read-only file system)

I have tried this with and without the WRITE_INTERNAL_STORAGE permission. There is no WRITE_INTERNAL_STORAGE permission in Android. How do I create this file for writing? You don’t, except perhaps on a rooted device, if your app is running with superuser privileges. You are trying to write to the root of internal storage, which apps do … Read more

Create and Share a File from Internal Storage

It is possible to expose a file stored in your apps private directory via a ContentProvider. Here is some example code I made showing how to create a content provider that can do this. Manifest <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.providertest” android:versionCode=”1″ android:versionName=”1.0″> <uses-sdk android:minSdkVersion=”11″ android:targetSdkVersion=”15″ /> <application android:label=”@string/app_name” android:icon=”@drawable/ic_launcher” android:theme=”@style/AppTheme”> <activity android:name=”.MainActivity” android:label=”@string/app_name”> <intent-filter> <action android:name=”android.intent.action.MAIN” /> … Read more