0

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,490
  • 12
  • 40
  • 60
  • 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

3 Answers3

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,577
  • 3
  • 24
  • 34
0

Hi here i am attaching the link of a tutorial explained.

http://www.mysamplecode.com/2012/06/android-internal-external-storage.html

and there are many discussions going on internet that you should root your phone in order to access the data from data/data folder and I am also attaching some links about the discussion, I hope these are also some of the links that are related to your question

where do i find app data in android

How to access data/data folder in Android device?

and as well as some links that makes out the things without rooting your phone i mean You can get access to /data/data/com*.* without rooting the device

http://denniskubes.com/2012/09/25/read-android-data-folder-without-rooting/

Community
  • 1
  • 1
Bharadwaja Bapatla
  • 3,281
  • 1
  • 12
  • 14
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" />
dharam
  • 7,739
  • 4
  • 37
  • 70