[英]File is not visible when phone sd card is connected to pc
我從android創建了一個excel文件,當我將手機連接到計算機,然后在計算機中我無法看到該文件。 這是為什么?
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) {
}
}
您需要重新啟動手機或重新連接到PC。
可能缺乏寫入文件的權限
WRITE_EXTERNAL_STORAGE
READ_EXTERNAL_STORAGE
它也可能是未安裝外部存儲器,請檢查:
Environent.getExternalStorageState();
PC的文件瀏覽器沒有立即刷新Android文件系統。
所以我建議你使用adb shell
命令。 它會立即顯示設備文件系統的更改。
$ adb devices
//獲取您的設備ID。 如果僅連接一個,則不需要此命令。
$ adb shell (-s your-device-id)
//輸入設備的文件系統。
shell$ cd sdcard/
//通常情況下,默認設備存儲的路徑是/sdcard
。 更改目錄,然后找到您的文件。
shell$ exit
//如果找到該文件,請退出adb shell
。
$ adb pull /sdcard/<parent-directory-path>/<file-name> <destination-path-on-your-PC>
//如果需要在系統上獲取此文件,請使用此命令。
如果找不到,則可能尚未創建該文件。 在這種情況下,您將檢查項目設置如下:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.