2014-09-04 35 views
0

我創建一個文件,該地址:無法看到的Android創建的文件在PC

Environment.getExternalStorageDirectory() + File.separator + "file.txt" 

我一個真正的設備上運行。當我從PC斷開設備並轉到文件瀏覽器程序時,我可以在我的路線中看到文件。但是當我將手機連接到PC並從我的電腦轉到它的驅動器時,我看不到該文件。

有什麼問題?

感謝

回答

0

使用MediaScannerConnection通知的新文件和目錄系統。

與PC的USB連接使用PTP或MTP協議,在PC上可以看到文件之前需要刷新相應的數據庫。

+0

現在正常工作。真的感謝! – 2014-09-04 16:17:58

0

嘗試使用這種方法:

public Boolean write(String fname, String fcontent){ 
      try { 
        String fpath = "/sdcard/"+fname+".txt"; 
        File file = new File(fpath); 
        // If file does not exists, then create it 
        if (!file.exists()) { 
          file.createNewFile(); 
        BufferedWriter bw = new BufferedWriter(fw); 
     bw.write(fcontent); 
     bw.close(); 
     Log.d("Suceess","Sucess"); 
     return true; 
     } catch (IOException e) { 
     e.printStackTrace(); 
     return false; 
     } } 
        FileWriter fw = new FileWriter(file.getAbsoluteFile()); 
        
   } 
+0

同樣的問題。我還使用了File file = new File(Environment.getExternalStorageDirectory(),「file.txt」);令人驚訝的是,我發現當我在eclipse中看到文件資源管理器時,我在mnt> sdcard> X中看到我的文件,其中X是我的手機SD卡中的第一個文件夾,其名稱以文件開頭的相同字母開頭。例如,我在名爲「far」的文件夾中看到file.txt或在名爲「kafe」的文件夾中看到kk.txt。但是即使在這些文件夾中,我也無法在PC中看到file.txt或kk.txt。 – 2014-09-04 15:14:49

+0

檢查這個官方文檔創建文件http://developer.android.com/training/basics/data-storage/files.html – 2014-09-04 15:25:23

相關問題