File outputFile = new File(path, clickedKey+".txt");
OutputStream fos = new FileOutputStream(outputFile);
fos.write(data.getBytes());
fos.close();
このコードは、パスに "ąóźżę" (ポーランド語の特殊文字) のような文字が含まれていない場合に機能します。パスにそれらのいずれかが含まれている場合は機能しfos.write
ますが、効果はありません (新しいファイルは「外部」パス名で作成されませんが、パスは存在します)。私の質問は、それを修正するにはどうすればよいですか?
「アストロ」や「ファイルマネージャー」などのファイル管理アプリは、このようなキャラクターでも問題なく動作します。
私もこれを試します:
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();
しかし、うまくいきません。