【问题标题】:Adding folder in Internal Storage in public?在公共内部存储中添加文件夹?
【发布时间】:2014-11-04 17:28:18
【问题描述】:

我正在创建 Excel 文件 将其存储在内部存储中,但我无法做到。它仅在应用存储目录中创建。在公共场合不可见。如何创建文件夹和存储那个文件夹中的文件?谁能知道帮我解决这个问题。

文件创建编码

 public String generate(String file_name,String path) {

    try {

        f = new File(activity.getFilesDir(), path);
        if (!f.exists()) {
           f.mkdirs();
        }


        file = new File(f.getAbsolutePath(), file_name);
        if (file.createNewFile()) {
            file.createNewFile();
        }

        wb_setting = new WorkbookSettings();
        wb_setting.setLocale(new Locale("en", "EN"));

        workbook = Workbook.createWorkbook(file, wb_setting);
        workbook.createSheet("Report", 0);
        excelSheet = workbook.getSheet(0);
        createLabel(excelSheet);
        createContent(excelSheet);

        workbook.write();
        workbook.close();

        file_path_alert_builder = new AlertDialog.Builder(activity);
        file_path_alert_builder.setTitle("File path");
        file_path_alert_builder.setMessage(""+file).setCancelable(true).setPositiveButton("OK",new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

                dialogInterface.dismiss();

            }
        });

        file_path_dialog = file_path_alert_builder.create();
        file_path_dialog.show();
    }catch (JXLException jxl_e) {
        jxl_e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

【问题讨论】:

    标签: android jxls


    【解决方案1】:

    您必须选择正确的路径来存储文件。有多种选择

    内部存储

    • 应用内部(最终用户无法从外部访问)
    • 缓存目录(系统空间不足可清空)

    外部存储(验证是否可用并使用)虽然是公共的,但有两种类型

    • 公开
    • 私有(用户和其他应用在技术上可以访问,因为它们位于外部存储上,它们是实际上不会为您的应用之外的用户提供价值的文件。)

    每个路径位置都可以通过 android 提供的不同 API 访问。见http://developer.android.com/training/basics/data-storage/files.html

    【讨论】:

    • 好的,但是一些流行的应用程序,如 What's、Viber、camscanner 应用程序有文件夹来显示内部存储中的文件。
    • 他们使用外部存储。可以使用getExternalFilesDir()。
    【解决方案2】:

    您所说的对公众可见是什么意思?其他应用程序访问?如果是这种情况,请使用: 改为getExternalFilesDir()

    【讨论】:

    • 当用户打开内部存储意味着文件夹将可见。
    • 那么你应该使用@Aun 建议的Environment.getExternalStoragePublicDirectory。请注意,“外部存储”可以是可移动存储介质(如 SD 卡)或内部(不可移动)存储
    猜你喜欢
    • 1970-01-01
    • 2011-08-11
    • 2021-09-08
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 2014-02-03
    相关资源
    最近更新 更多