简体   繁体   English

无法从计算机在 Android 上的外部存储中查看公开创建的文件

[英]Cannot see publicly created file in external storage on Android from computer

I want save a somewhat large json string to a file, then access it from my computer so I can view it and put in a json validator to find out where my problem is.我想将一个有点大的 json 字符串保存到一个文件中,然后从我的计算机访问它,以便我可以查看它并放入一个 json 验证器以找出我的问题所在。 This is for debugging only.这仅用于调试。 I've tried saving to internal and external storage but I cant access my file for the life of me.我尝试保存到内部和外部存储,但我终生无法访问我的文件。 I can see it from adb shell, but when I try to adb pull it, its not there.我可以从 adb shell 看到它,但是当我尝试 adb pull 它时,它不在那里。

I can also see my file from other apps (like DropBox) on the device, but I cant see it from a computer.我也可以从设备上的其他应用程序(如 DropBox)看到我的文件,但我无法从计算机上看到它。

This is the most recent code I tried and should put it in the public downloads folder, but its not there:这是我尝试过的最新代码,应该将它放在公共下载文件夹中,但它不在那里:

File path = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DOWNLOADS);
path.mkdir();

externalFile = new File(path,JSON_FILE_NAME);

OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(externalFile));
//write stuff
out.close()

I HAVE added permission to write to external storage.我已经添加了写入外部存储的权限。

When you are using MTP to view the files on your PC, they will only show up once the MediaScanner has found them.当您使用 MTP 查看 PC 上的文件时,它们只会在MediaScanner找到后才会显示。 You can use the following code to force the MediaScanner to scan your file:您可以使用以下代码强制MediaScanner扫描您的文件:

MediaScannerConnection.scanFile(getApplicationContext(),
            new String[]{externalFile.toString()}, null, null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM