android - Android 文件名中的外来字符

标签 android sd-card createfile

File outputFile = new File(path, clickedKey+".txt");
OutputStream fos = new FileOutputStream(outputFile);
fos.write(data.getBytes());
fos.close();

当路径不包含以下字符时,这段代码有效:“ąóźżę”(来自波兰语的特殊字符)。 如果路径包含它们中的任何一个,fos.write 有效但没有效果(新文件不是使用“外部”路径名创建的,但路径存在)。 我的问题是:我能做些什么来修复它?

“Astro”、“文件管理器”等文件管理器应用程序可以毫无问题地处理此类字符。

我也试试这个:

Charset charset = Charset.forName("UTF-8");
CharsetEncoder encoder = charset.newEncoder();
CharsetDecoder decoder = charset.newDecoder();

ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(clickedKey+".txt"));
CharBuffer cbuf = decoder.decode(bbuf);
String s = cbuf.toString();

bbuf = encoder.encode(CharBuffer.wrap(path));
cbuf = decoder.decode(bbuf);
String path_s = cbuf.toString();

File outputFile = new File(path_s, s);
OutputStream fos = new FileOutputStream(outputFile);
fos.write(tab.getBytes());
fos.close();

但效果不佳。

最佳答案

当我的手机通过 ADB 连接并且我正在使用 DDMS 检查新文件时,“外部”路径上没有任何文件。但实际上,文件在手机里!

我检查过,直接在我的手机中使用文件管理器:) 很奇怪。但是我解决了这个问题。

关于android - Android 文件名中的外来字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7204143/

相关文章:

android - 错误 : Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath' : Could not resolve com. squareup.retrofit2 :retrofit:2. 3.0

winapi - Windows : How to intercept Win32 disk I/O API

android - 如何隐藏启动屏幕中间的应用程序图标/启动器图标

android - 如何从使用 diffutil 的 recyclerview 中删除项目?

android - 为什么 sdcard 旧版 getCanonicalPath 在 Android 4.2 操作系统中未模拟/0?

android - Android 中的 EACCESS 权限被拒绝

sd卡的linux设备节点作为mmcblk访问CSD寄存器

windows - 如何打开 NTFS 元数据/系统文件 : $LogFile, $Volume,$Bitmap?

C++ COM口的打开、读写

android - Android : Could not find class 'com.google.android.gms.analytics.Tracker' 中的 Google Analytics v4