简体   繁体   English

如何将具有特殊字符的文件传输到Android SD卡?

[英]How can I transfer a file with special character to my Android SDcard?

Recently I'm in trouble about creating file in Android SD card with special character from iPhone. 最近,我在用iPhone特殊字符在Android SD卡中创建文件时遇到麻烦。

My device : Galaxy Note4 KitKat. 我的设备:Galaxy Note4 KitKat。 My PC : Window7 我的电脑:Window7

I got a file from iPhone to my PC. 我收到了从iPhone到PC的文件。 This file contains an emoticon ( http://chars.suikawiki.org/string?s=%F0%9F%90%8D ) I could transfer this file to internal SDcard from my PC but I could not transfer to removable SDcard. 该文件包含一个表情符号( http://chars.suikawik​​i.org/string?s=%F0%9F%90%8D )我可以从我的PC将此文件传输到内部SD卡,但无法传输到可移动SD卡。

Even I can't transfer copied file from internal to removable, too.( I used FileOutputStream, File.createNewFile to copy) 即使我也无法将复制的文件从内部传输到可移动文件。(我使用FileOutputStream,File.createNewFile进行复制)

I suspected SDcard's file system and tried to other FAT16(2GB sandisk Sdcard ), exFAT(64GB samsung SDcard). 我怀疑SDcard的文件系统,并尝试使用其他FAT16(2GB sandisk Sdcard),exFAT(64GB三星SDcard)。

But I failed both. 但是我都失败了。

I tried to found file system spec but i found nothing related. 我试图找到文件系统规范,但没有发现任何相关信息。 I also suspected reserved file title characters, but it was not related. 我也怀疑保留文件标题字符,但没有关系。

In short, 简而言之,

  1. Why cannot transfer this file to removable SDcard? 为什么无法将此文件传输到可移动SD卡?

  2. How to copy programmatically this file to SDcard without renaming ? 如何以编程方式将此文件复制到SDcard而无需重命名?

===== add snippet ===== =====添加代码段=====

Below special character seems emoticon in Android device file browser but in my PC, it looks ordinal special character. 下面的特殊字符在Android设备文件浏览器中似乎是图释,但在我的PC中,它看起来是序数特殊字符。

new File("/storage/emulated/0/🐍🐢🐙🐌.txt").createNewFile(); 新File(“ / storage / emulated / 0 /🐍🐢🐙🐌.txt”)。createNewFile(); //internal storage. //内部存储器。 work. 工作。

new File("/storage/extSdCard/🐍🐢🐙🐌.txt").createNewFile();//removable storage. new File(“ / storage / extSdCard /🐍🐢🐙🐌.txt”)。createNewFile(); //可移动存储。 not work 不行

I stumbled onto a similar issue with saving to SD. 我偶然发现了一个类似的问题,即保存到SD。 It appears to be a security issue. 这似乎是一个安全问题。 You now need to use the Storage Access Framework See Here . 现在,您需要使用Storage Access Framework, 请参见此处

You could use the files allocated to your Application though and not have to use the Storage Access Framework. 但是,您可以使用分配给应用程序的文件,而不必使用Storage Access Framework。 One way to access your Applications data directory is by either using: 访问应用程序数据目录的一种方法是使用以下任一方法:

ContextCompat.getExternalFilesDirs(context, type)

Which would be backwards compatible. 这将向后兼容。 Or you could use the following for Lollipop Users 或者您可以对Lollipop用户使用以下内容

Context.getExternalMediaDirs()

Each of this method will give you 2 Directories. 每种方法都会给您2个目录。 1 for internal memory and other for SD (If device has slot). 1用于内部存储器,其他用于SD(如果设备具有插槽)。 From here you can save all your application specific data. 在这里,您可以保存所有特定于应用程序的数据。

BE WARNED: this data will be deleted if user ever uninstalls your application. 警告:如果用户卸载了您的应用程序,此数据将被删除。

Hope this helped! 希望这对您有所帮助!

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

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