유니 코드 파일 (UTF-8)을 읽고 다른 파일에 다시 쓰고 싶습니다.유니 코드 파일 IO in Codename One
코드는 내가 읽고 내가 심지어
text = com.codename1.io.Util.readToString(in,"UTF-8");
및
DataInputStream dis = new DataInputStream(in);
text = com.codename1.io.Util.readUTF(dis);
을 시도하지만 유니 코드를 읽을 점점되지 있지 않다
final String textFile = "/readme.txt";
String text = "";
InputStream in = Display.getInstance().getResourceAsStream(null, textFile);
if (in != null){
try {
text = com.codename1.io.Util.readToString(in);
in.close();
} catch (IOException ex) {
System.out.println(ex);
text = "Read Error";
}
}
(Textscreen in Codename One, how to read text file?에서와 같이)이며, 사용 . 내가 파일을 생성 관찰
작성하기위한내가 뭐하는 거지,
String content = "Some Unicode String";
OutputStream stream = fs.openOutputStream(path + "/" + fileName);
stream.write(content.getBytes());
stream.close();
과 노력,
DataOutputStream dos = new DataOutputStream(stream);
dos.writeUTF(content);
은 ANSI 인코딩입니다.
업데이트 : 솔루션 @ 샤이의 회신 사항에 따라
,
읽기 :
// For text file in package structure
InputStream in = Display.getInstance().getResourceAsStream(null, "/" + textFile);
// For file in file system
InputStream in = fs.openInputStream(textFile);
if (in != null) {
try {
text = com.codename1.io.Util.readToString(in, "UTF-8"); // Encoding
in.close();
} catch (IOException ex) {
text = "Read Error";
}
}
쓰기 :
OutputStream stream = fs.openOutputStream(textFile);
stream.write(content.getBytes("UTF-8"));
stream.close();
도움 주셔서 감사합니다. :) –