SoulRayder
SoulRayder

Reputation: 5166

.xlsx file getting created outside the folder, but not inside it

I am trying to create a .xlsx file inside a folder ( programmatically created by me) using the jspreadsheet-1.0.jar. The file gets created with around 3 KB size and I can open it and view it, if I create it outside the folder in the path /storage/sdcard0, but if I create within the folder, it just shows a 0 KB file which cannot be opened. My code is as follows:

Folder creation:

    String FOLDERNAME="/foldername";
                File dir = new File(Environment.getExternalStorageDirectory(), FOLDERNAME);
                if(!dir.exists())
                {
                    dir.mkdir();
                }

File generation (within a folder):

public void generate(Context mainContext)
{
     Worksheet sheet1 = new Worksheet();
           sheet1.set("A1",new Cell(100));

          context = mainContext;

        Workbook book1 = new Workbook();
        book1.getSheets().add(sheet1);

        try {
                     book1.save(Environment.getExternalStorageDirectory().getAbsolutePath()+"/foldername/file.xlsx");
              } catch (IOException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
              }

        new SingleMediaScanner(context,Environment.getExternalStorageDirectory().getAbsolutePath()+"/foldername/file.xlsx");
}
}

Upvotes: 0

Views: 102

Answers (1)

Priya
Priya

Reputation: 489

Try using

 book1.save(Environment.getExternalStorageDirectory()+"/foldername/file.xlsx");

instead of

  book1.save(Environment.getExternalStorageDirectory().getAbsolutePath()+"/foldername/file.xlsx");

Upvotes: 1

Related Questions