2012-04-05 215 views
0

我正在嘗試編寫一個應用程序,將數據添加到SD卡上的現有電子表格。JXL和Android I/O權限被拒絕

我有一個問題,當我嘗試創建一個可寫的工作簿:

outputWorkbook = Workbook.createWorkbook(outputWorkbookFile,inputWorkbook);

我得到的logcat錯誤在Eclipse:

04-05 13:29:54.809: W/System.err(32653): java.io.FileNotFoundException: /mnt/sdcard/Dev/Spreadsheets/in.xls (Permission denied)

我可以讀取輸入文件並獲取單元格的內容,我可以實例化一個可寫入的工作簿或實例化一個輸入工作簿,但不能同時存在。

private void doStuff() { 
    File directory = Environment.getExternalStorageDirectory(); 
    inputWorkbookFile = new File(directory + "/Dev/Spreadsheets/in.xls"); 
    outputWorkbookFile = new File(directory + "/Dev/Spreadsheets/out.xls"); 

    try { 

     // Put data into an array for easier iteration 
     double data[]; 
     data = new double[7]; 
     data[0] = income; 
     data[1] = diesel; 
     data[2] = carHire; 
     data[3] = radio; 
     data[5] = 0; 
     data[6] = itemCost; 

     inputWorkbook = Workbook.getWorkbook(inputWorkbookFile); 
     Log.e("Testing", "Opened workbook"); 

     if (isExternalStorageAvailable() && isExternalStorageReadable()) { 
      Log.e("Testing", "storage readable and available"); 
      outputWorkbook = Workbook.createWorkbook(outputWorkbookFile, 
        inputWorkbook); 
     } 

回答

0

您需要在您的AndroidManifest uses-permission標籤聲明許可android.permission.WRITE_EXTERNAL_STORAGE

+0

奇妙的工作。我昨天晚上想到了那個,但忘了試一下,我的頭被那個點炸了。謝謝 – 2012-04-05 13:48:27