文件在 Android 文件浏览器中可见时无法在 Windows 资源管理器中查看该文件
通过我的 Android 程序,我编写了一个如下文件:
String file = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Files/hello.txt";
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(str+"\n"); \\yeah string has a value there
writer.close();
现在,当我进入 Android 的“Astro”文件浏览器时,我可以在 /mnt/sdcard/Files
中看到文件 hello.txt,但是当我挂载Windows 中的 SD 卡上,我只能看到该文件夹中的其他 4 个文件,但看不到 hello.txt。
在 Windows 本身中,我什至尝试取消选中隐藏隐藏文件选项,只是为了确保该文件不是隐藏的,但只是不可见。
我什至尝试将文件写入 SD 卡的根目录中,但又出现同样的问题。现在我很惊讶我怎么可能在 Android 中看到该文件,但在 Windows 中却看不到。在 Android 中,我什至检查了文件内容,一切看起来都很好。
可能是什么问题?难道是我写文件的方式不对?
PS:是的,添加了清单权限android.permission.WRITE_EXTERNAL_STORAGE
。
Through my Android program I wrote a file like this:
String file = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Files/hello.txt";
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(str+"\n"); \\yeah string has a value there
writer.close();
Now when I go to Android's "Astro" File browser, I can see the file hello.txt in /mnt/sdcard/Files
but when I mount the sdcard in Windows, I can only see 4 other files which were there in that folder but not hello.txt.
In Windows itself, I even tried to uncheck the hide hidden files option just to ensure that the file is not hidden but it's just not visible.
I even tried to write the file in root of the sdcard but again same problem. Now I'm surprised that how is it possible that I can see the file in Android but not in Windows. In Android I've even checked the file contents and everything looks fine.
What could be the problem? Is the way I'm writing the file wrong?
PS: yes the Manifest permission android.permission.WRITE_EXTERNAL_STORAGE
is added.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,我知道为什么会这样了。即使该程序写入的文件位于 SD 卡上并且文件编写器已关闭,我也无法访问该文件。
实际上,即使我们按“后退”按钮,程序也会继续运行,除非我转到“设置”>应用领域>>管理应用程序> “强制停止”
这只是基于我的观察,我希望有人能用事实和解决方案发布更好的答案。
编辑:我会相应地更新我的问题。
编辑:按照元上的建议,我发布了一个新问题
无法在 Windows 中看到由 SD 卡上的 Android 应用程序写入的文件,除非我“强制关闭”该应用程序
Ok, I figured out why it was happening.
Actually even if we press "Back" button, the program keeps running and unless I go to
Settings > Applications > Manage Applications > "Force Stop" <application>
I can't access the file written by this program even if it is on sd card and even if the filewriter has been closed.This is just based on my observation and I'd like someone to post a better answer with facts and with solution.
edit: I'll update my question accordingly.
edit: as recommended on meta I've posted a new question
Can't see a file in Windows written by an android app on sd-card unless I “Force Close” the app
如果情况更糟,最严重的断开连接,请重新启动并重新连接您的 Android 设备。然后文件应该会显示。
If worse comes to worst disconnect, reboot and reconnect your Android device. The files should show up then.
我找到了一个解决方法。
我编写了一个例程来捕获手机加速度计的数据。我注意到,如果该文件具有 .dat 或 .txt 扩展名,我就看不到它,也无法将其复制到我的电脑上。
通过在 Android 端不为文件分配文件扩展名,我发现它可以从 PC 上看到。复制到PC上并添加.txt扩展名后,就可以在PC上查看了。
I have found a workaround.
I wrote a routine to capture data from the phone accelerometer. I noticed if the file had a .dat or .txt extension I could not see it and could not copy it to my PC.
By not assigning a file extension to the file on the Android side, I found it would be visible from the PC. After copying it to the PC and adding a .txt extension, it could then be viewed on the PC.
显示隐藏的文件和文件夹
To display hidden files and folders