foreign chars in file name on Android
File outputFile = new File(path, clickedKey+".txt");
OutputStream fos = new FileOutputStream(outputFile);
fos.write(data.getBytes());
fos.close();
This piece of code works when a path doesn't contain chars like: "ąóźżę" (special characters from polish language).
If the path contains any of them fos.write
works but there's no effect (new file isn't created with "foreign" path name, but the path exists).
My question is: what can I do to fix it?
File managers apps like "Astro", "File Manager" etc. work without any trouble with such characters.
I try also this:
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();
but it doesn't 开发者_JS百科work as well.
When my phone was connected by ADB and I was checking new files with DDMS, there wasn't any file on "foreign" path. But in fact, files were in phone!
I checked it, with file manager direct in my phone :) It strange. But I solved the problem.
Did you check the encoding? in eclipse: Edit > set Encoding > utf-8 or 16
精彩评论