gpt4 book ai didi

android - 在公开的内部存储中添加文件夹?

转载 作者:行者123 更新时间:2023-11-30 02:34:52 26 4
gpt4 key购买 nike

我正在创建 Excel 文件 以将其存储在内部存储中,但我做不到。它仅在应用程序存储目录中创建。在公共(public)场合不可见。如何创建文件夹和存储该文件夹中的文件?任何人都可以帮助我解决这个问题。

文件创建编码

 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;
}

最佳答案

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

内部存储

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

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

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

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

关于android - 在公开的内部存储中添加文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26731195/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com