2017-08-17 83 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以引用示例代码。