Jexcel APIを使用してExcelファイルを作成し、自分のアプリケーションで携帯電話に書き込もうとしています。アプリを実行すると、FileNotFoundException
がスローされます。私は別のそのような質問への答えに応じてテキストファイルを作成しようとしましたが、同じエラーがスローされます。私はマニフェストに適切な権限を与えましたが、私はまだ問題を特定することはできません。 助けてください。Androidでファイルを作成しようとしたときにFileNotFoundExceptionが発生する
はここに私のコード実行に
public WritableWorkbook createWorkbook(String fileName){
//Saving file in external storage
File sdCard = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File directory = new File(sdCard.getAbsolutePath() + "/bills");
//create directory if not exist
if(!directory.isDirectory()){
directory.mkdirs();
}
//file path
file= new File(directory, fileName);
if (file.exists())
Log.e(taf,"file created");
else
Log.e(taf,"file not created");
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
wbSettings.setUseTemporaryFileDuringWrite(true);
WritableWorkbook workbook;
workbook=null;
try {
workbook = Workbook.createWorkbook(file, wbSettings);
Log.i(taf,"workbook created");
//Excel sheet name. 0 represents first sheet
WritableSheet sheet = workbook.createSheet("MyShoppingList", 0);
try {
sheet.addCell(new Label(0, 0, "Subject")); // column and row
sheet.addCell(new Label(1, 0, "Description"));
String title = "blaj";
String desc = "nxjdncj";
int i = 1;
sheet.addCell(new Label(0, i, title));
sheet.addCell(new Label(1, i, desc));
} catch (WriteException e) {
e.printStackTrace();
}
workbook.write();
try {
workbook.close();
} catch (WriteException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return workbook;
}
で、ログメッセージ「を作成していないファイルは、」印刷されます。私はアンドロイドに新しいので、最も基本的な問題を指摘してください。
ありがとうございます。
あなたのAndroidバージョンは6.0ですか? –
はい。プレマシュマロデバイスでも機能します。私は、あなたが実行時の権限を追加する必要があるマシュマロデバイスのためにそれを読んだが、私は正確にそれらを追加する方法を知っていない。 –