-2

This is my application memory path /data/data/com.myexample.folder/files and it works fine but when I create a new directory like this /data/data/com.myexample.folder/files/photos, it is not created and I wonder what's wrong? How do I create a new folder inside application.

public void loadFeed();
String file paths="data/data/com.myapplication.myfolder/files";
File outputFiles= new file(filePaths);
File files1=outputFile1.listFiles();
von v.
  • 16,868
  • 4
  • 60
  • 84
nazeer
  • 1
  • 3
  • http://stackoverflow.com/a/8124723/931982 – stinepike Apr 16 '13 at 06:35
  • Have you given the permission in manifest? – Abx Apr 16 '13 at 06:36
  • check it [SO question](http://stackoverflow.com/questions/2130932/how-to-create-directory-automatically-on-sd-card) – jimpanzer Apr 16 '13 at 06:39
  • this path is work fine String file paths="data/data/com.myapplication.myfolder/files" but when i add new sub directory like this String file paths="data/data/com.myapplication.myfolder/files/photos" is not display anything – nazeer Apr 16 '13 at 06:39
  • possible duplicate of [Android create folders in Internal Memory](http://stackoverflow.com/questions/8124612/android-create-folders-in-internal-memory) – Marcin Orlowski Apr 16 '13 at 06:40

3 Answers3

1

For your own directory in file storage:

FileOutputStream outStream = null;
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File(sdCard.getAbsolutePath() + "/camtest");
dir.mkdirs();
String fileName = String.format("%d.jpg", System.currentTimeMillis());
File outFile = new File(dir, fileName);
outStream = new FileOutputStream(outFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);

For saving in sub directory inandroid public folders say DCIM:

use File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);

Mainly, make sure that your app has the storage permission enabled:

Go to Device Settings>Device>Applications>Application Manager>"your app">Permissions>Enable Storage permission!

Shravan DG
  • 527
  • 1
  • 5
  • 16
0

Call openFileOutput() with the name of the file and the operating mode.

    String FILENAME = "hello_file";
    String string = "hello world!";

    FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
    fos.write(string.getBytes());
    fos.close();
Arun C
  • 9,035
  • 2
  • 28
  • 42
0

just use this way:

public void createFile(Context c) throws IOException{
     String FILENAME = timeStamp();
     String string = "hello world!";

     FileOutputStream fos = c.openFileOutput(FILENAME, Context.MODE_PRIVATE);
    fos.write(string.getBytes());
    fos.close();


}
Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177