2014-09-04 31 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

相关问题