在 /data/user/0/[package name]/files 目录中找不到文件,但在 /data/data/[package name]/files 目录中找到

top*_*741 5 java filesystems io android android-file

我正在从服务器下载一个 zip 文件到我的内部存储。它保存到/data/data/[package name]/files目录中,我可以使用 Android Studio 中的设备文件资源管理器查看它。但是当我尝试访问它以解压缩它时,出现以下错误:

java.io.FileNotFoundException: thezip.zip: open failed: ENOENT (No such file or directory)
Run Code Online (Sandbox Code Playgroud)

当我打电话时:

context.getFileDir();
Run Code Online (Sandbox Code Playgroud)

它给了我以下目录:

/data/user/0/[package name]/files
Run Code Online (Sandbox Code Playgroud)

这是一个符号链接

/data/data/[package name]/files directory
Run Code Online (Sandbox Code Playgroud)

所以我应该可以访问 zip 文件,不是吗?

我在这里缺少什么?我希望任何使用该应用程序的用户都可以访问 zip 文件夹中的文件。帮助!

编辑:这是代码:

class DownloadFileAsync extends AsyncTask<String, String, String> {
    private Context context;
    private String fileName;

    public DownloadFileAsync(Context context, String fileName){
        this.context = context;
        this.fileName = fileName;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

    }

    @Override
    protected String doInBackground(String... aurl) {
        downloadZipFile(aurl[0]);
        try {
            unzipFolder(fileName);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;

    }
    protected void onProgressUpdate(String... progress) {
        Log.d("ANDRO_ASYNC",progress[0]);

    }

    @Override
    protected void onPostExecute(String unused) {

    }

    private void downloadZipFile(String link){
        int count;

        try {

            URL url = new URL(link);
            URLConnection connection = url.openConnection();
            connection.connect();

            int lenghtOfFile = connection.getContentLength();
            Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);

           // File file = new File(context.getFilesDir(), fileName);
            File file = new File(context.getFilesDir(), fileName);
            Log.d("zzzz", file.toString());
            InputStream input = new BufferedInputStream(url.openStream());
            FileOutputStream output = new FileOutputStream(file);

            byte data[] = new byte[1024];

            long total = 0;

            while ((count = input.read(data)) != -1) {
                total += count;
                publishProgress(""+(int)((total*100)/lenghtOfFile));
                output.write(data, 0, count);
            }

            output.flush();
            output.close();
            input.close();
        } catch (Exception e) {}
    }

    private void unzipFolder(String zippedFile) throws IOException {
            //Log.d("zzzz", context.getFilesDir().toString());

        byte[] buffer = new byte[1024];
        ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zippedFile));
        ZipEntry zipEntry = zipInputStream.getNextEntry();
        while (zipEntry != null){
            String aFile = zipEntry.getName();
            File newFile = new File(context.getFilesDir(), aFile);
//            File newFile = new File(context.getFilesDir(), aFile);
            FileOutputStream fileOutputStream = new FileOutputStream(newFile);
            int len;
            while ((len = zipInputStream.read(buffer)) > 0){
                fileOutputStream.write(buffer, 0, len);
            }
            fileOutputStream.close();
            zipEntry = zipInputStream.getNextEntry();
        }

        zipInputStream.closeEntry();
        zipInputStream.close();

    }
}
Run Code Online (Sandbox Code Playgroud)