gpt4 book ai didi

java - 无法访问我在 PC 上的 Android 应用程序中创建的文件

转载 作者:行者123 更新时间:2023-11-30 03:33:56 24 4
gpt4 key购买 nike

我写了一些应用程序,将一些数据写入SD卡上的外部存储器(实际上我没有SD卡,但路径是/sdcard/map/file。当我用ES文件浏览器查看手机上的文件时,我可以查看并打开文件,但我在 PC 上看不到该文件。有人知道可能是什么问题吗?

private void createMapFile(String fileName, byte mapBytes[]) throws IOException {       
File filePath = new File(Environment.getExternalStorageDirectory().getPath() + "/map/"+ fileName);

FileOutputStream os = new FileOutputStream(filePath, true);
os.write(mapBytes);
os.close();
}

这是我用来将二进制数据数组写入文件的方法。

最佳答案

这样就可以了:

File myFile;
...
// myFile creates somewhere here
...
MediaScannerConnection.scanFile(context, new String[]{myFile.getAbsolutePath()}, null, null);

之后,您将立即可以在连接的 PC 上看到创建的文件。

关于java - 无法访问我在 PC 上的 Android 应用程序中创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16932608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com