1

I need to download some pdf files into data/data/com.**.* folder.

Those files are application specific and only application should read and display it that's the reason storing on data/data/com.**.* folder.

Please let me know how to download into that folder and open/read it in the application.

I know how to download it into SD card, but I do not have idea to downloading to application specific folder.

Please let me know some code examples to do this and also I need to know the capacity/size of the data/data/com.**.* folder.

brig
  • 3,721
  • 12
  • 43
  • 61
  • If you know how to download to SD card then you can do that too to your app specific directory in internal memory. All code is exactly the same. So I don't understand why you ask for the obvious. You only have to change a path. – greenapps May 19 '14 at 07:47

2 Answers2

2

As long as you want write your own applications Data folder, you can create a FileOutputStream like this FileOutputStream out = new FileOutputStream("/data/data/com.**.*/somefile"); than use that output stream to save file. Using the same way you can create a FileInputStream and read the file after.

You will get Permission Denied if you try to access another application's data folder.

I am not sure for capacity but you can calculate the size of the data folder using this

File dataFolder = new File("/data/data/com.**.*/");
long size = folderSize(dataFolder);

...

public static long folderSize(File directory) {
    long length = 0;
    for (File file : directory.listFiles()) {
        if (file.isFile())
            length += file.length();
        else 
            lengthlong += folderSize(file);
    } 
    return length;
} 
Onur
  • 5,617
  • 3
  • 26
  • 35
0

To Write file

FileOutputStream out = new FileOutputStream("/data/data/your_package_name/file_name.xyz"); 

To Read file

FileInputStream fIn = new FileInputStream(new File("/data/data/your_package_name/file_name.xyz"));

Now you have your input stream , you can convert it in your file according to the file type . I am giving you example if your file is contain String data the we can do something like below ,

 BufferedReader myReader = new BufferedReader(
                    new InputStreamReader(fIn));
            String mDataRow = "";
            String mBuffer = "";
            while ((mDataRow = myReader.readLine()) != null) {
                mBuffer += mDataRow + "\n";
            }

Remember to add write file permission to AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
dharmendra
  • 7,835
  • 5
  • 38
  • 71