user1792771
user1792771

Reputation: 99

I can't find any file in the Assets folder

I have a tar.gz file [1.5 MB size] into assets folder and I'm trying to move it to /data/data//. I'm trying to do this in a secondary activity (not in the main activity). The code:

 try {
        Log.d("chiri", Arrays.toString(getAssets().list(".")));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    try {
        InputStream fileInput = getAssets().open("nmap.tar.gz");
        OutputStream fileOutput = new FileOutputStream("/data/data/com.example.pentesting/nmap.tar.gz");
        byte[] buffer = new byte[1024];
        int length;
        while ((length = fileInput.read(buffer))>0){
            fileOutput.write(buffer, 0, length);
        }
} catch (IOException e) {
        Log.e("chiri", e.getLocalizedMessage(), e);
}

The problem is getAssets seems to be empty.

I saw that there are many topics on this problem but I couldn't figure out where is my problem. I saw that this can be a problem because the file is bigger then 1MB but i tried the think with a .txt file of 300bytes, but I couldn't find it too.

Any idea ?

Upvotes: 0

Views: 1402

Answers (2)

John Igzie
John Igzie

Reputation: 1

You can try .zip instead of .tar.gz, it worked for me.

Upvotes: 0

Kumar Bibek
Kumar Bibek

Reputation: 9117

The correct path to the assets folder should be specified like this.

file:///android_asset/nmap.tar.gz

And then you should be able to access the file.

The other way, which you are trying also would work:

Fix this line, by removing the dot, and you will see the list of files get printed.

Log.i("chiri", Arrays.toString(getAssets().list("")));

Upvotes: 1

Related Questions