删除下载目录中的文件

问题描述 投票:0回答:1

几个月前,我曾被帮助创建一个应用程序,而我正努力使它自己发展,这并不像我想要的那么容易。

我想删除在下载目录中创建的文件。我将此文件夹用作缓存文件夹,以共享应用程序中存储的声音。这是股票期权的示例(很好,但是我不知道我应该把outputFile.delete();行放在哪里...)

case R.id.partage:
            File outputFile = new File("");
            InputStream is = getResources().openRawResource(((Sound) adapter.getItem(index)).getMpsound());

            try {
                byte[] buffer = new byte[is.available()];
                is.read(buffer);
                File outputDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                outputFile = new File(outputDir, getResources().getResourceEntryName(((Sound) adapter.getItem(index)).getMpsound()) + ".mp3");
                OutputStream os = new FileOutputStream(outputFile);
                os.write(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("audio/*");
            share.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", outputFile));
            share.putExtra(Intent.EXTRA_TEXT, "\"" + ((Sound) adapter.getItem(index)).getTitre_show() + "\" shared by my app");
            startActivity(Intent.createChooser(share, "Share Sound File"));
            return true;

任何想法?

java android delete-file
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.