在android中编写excel表格时找不到文件



我有一个程序,我想发送一些数据到使用jxl库的excel表。我正在遵循一个教程,并有以下代码片段,我认为应该创建一个.xls文件与一个表和一些数据。然而,我得到一个文件没有发现错误与我给的任何路径。如果我没有输入任何路径,虽然我在清单中有读/写内部/外部权限,但有只写系统错误。如果有人能指出这个错误,我会很感激,因为我对java/android还是有点陌生。

         try {
                String exlFile = "Workbook1.xls";
                WritableWorkbook writableWorkbook = Workbook.createWorkbook(new File("/Users/xxxxxx/Documents/", exlFile));
                WritableSheet writableSheet = writableWorkbook.createSheet("Sheet1test", 0);
                //Create Cells with contents of different data types.
                //Also specify the Cell coordinates in the constructor
                Label label = new Label(0, 0, "Label (String)");
                DateTime date = new DateTime(1, 0, new Date());

                //Add the created Cells to the sheet
                writableSheet.addCell(label);
                writableSheet.addCell(date);

                //Write and close the workbook
                writableWorkbook.write();
                writableWorkbook.close();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (RowsExceededException e) {
                e.printStackTrace();
            } catch (WriteException e) {
                e.printStackTrace();
            }
错误:

java.io.FileNotFoundException: /Users/xxxxxx/Documents/Workbook1.xls (No such file or directory)

java.io。FileNotFoundException:系统找不到指定的文件

例如,如果你把你的项目结构改成ProjectRootsrcresourcesword.txt,你可以这样:

InputStream is = hangman1 .class. getresourcesstream ("/resources/word.txt");BufferedReader = new BufferedReader(new InputStreamReader(is));

变化

(new File("/Users/xxxxxx/Documents/", exlFile));

 (new File(Environment.getExternalStorageDirectory(), exlFile));

最新更新