问题
am create the Excel file to store it in Internal storage,but am not able to do.It Create only inside the app storage directory.Not to visible in public.How to create folder and store the file in that folder?Can anyone one know help me to solve this issue.
File Creation coding
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;
}
回答1:
you have to choose the right path where to store the files. There are multiple options
Internal storage
- internal to app (not accessible for end users from outside)
- cache directory (it can be cleared if system is running out of space)
External Storage (verify if it is available and use it) Although it is public there are 2 types
- public
- private (technically accessible by the user and other apps because they are on the external storage, they are files that realistically don't provide value to the user outside your app. )
each path location can be accessed with different API provided by android. see http://developer.android.com/training/basics/data-storage/files.html
回答2:
What you mean by visible to public? Access by other applications? If that is the case, using:
getExternalFilesDir()
instead
来源:https://stackoverflow.com/questions/26731195/adding-folder-in-internal-storage-in-public