2017-08-17 86 views
3

當我將手機連接到計算機時,我創建了一個來自android的excel文件,然後在計算機中無法看到該文件。這是爲什麼?當手機SD卡連接到電腦時,文件不可見

Workbook wb = new HSSFWorkbook(); 
    Cell c = null; 

    //Cell style for header row 
    CellStyle cs = wb.createCellStyle(); 

    //New Sheet 
    Sheet sheet1 = null; 
    sheet1 = wb.createSheet("Meter Readings"); 

    // Generate column headings 
    Row row = sheet1.createRow(1); 

    c = row.createCell(0); 
    c.setCellValue("Flat Number"); 
    c.setCellStyle(cs); 

    sheet1.setColumnWidth(0, (15 * 200)); 

    // Create a path where we will place our List of objects on external storage 
    File file = new File(context.getExternalFilesDir(null),fileName); 
    FileOutputStream os = null; 

    try { 
     os = new FileOutputStream(file); 
     wb.write(os); 
     Log.w("FileUtils", "Writing file" + file); 
     success = true; 
     //os.close(); 
    } catch (IOException e) { 
     Log.w("FileUtils", "Error writing " + file, e); 
    } catch (Exception e) { 
     Log.w("FileUtils", "Failed to save file", e); 
    } finally { 
     try { 
      if (null != os) { 
       os.close(); 
      } 
     } catch (Exception ex) { 
     } 
    } 
+0

你的日誌說什麼? – GhostCat

回答

0

您需要重新啓動手機或重新連接到PC。

+0

感謝rply,是否沒有其他選擇做Girish? – Raghavendra

+0

即使重新連接後也不會顯示 – Raghavendra

+0

您可以重新啓動設備並檢查嗎? –

0

可能是缺少權限寫入文件

WRITE_EXTERNAL_STORAGE 
READ_EXTERNAL_STORAGE 

它也可能是外部存儲設備未安裝,請與:

Environent.getExternalStorageState(); 
0

PC的文件瀏覽器沒有刷新Android文件系統立即。

因此,我建議您使用adb shell命令。它會立即顯示您的設備文件系統的變化。

  1. $ adb devices //獲取您的設備ID。如果僅連接一個,則此命令不是必需的。

  2. $ adb shell (-s your-device-id) //輸入到您的設備的文件系統。

  3. shell$ cd sdcard/ //通常情況下,默認設備存儲路徑爲/sdcard。改變目錄然後找到你的文件。

  4. shell$ exit //如果找到該文件,請退出adb shell

  5. $ adb pull /sdcard/<parent-directory-path>/<file-name> <destination-path-on-your-PC> //如果您需要在系統上獲取此文件,請使用此命令。

如果找不到,該文件可能尚未創建。在這種情況下,您將檢查項目設置如下:

  1. AndroidManifest.xml設置<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>如果要是下API 19

  2. 您的應用程序支持實現RuntimePermission常規您的應用程序支持超過21 API

    根據this page,將在Android 6.0或更高版本上運行應用時授予權限。

    有關實現,請檢查this post以引用示例代碼。