Write non english characters using a RandomAccessFile in java -
i trying write text file using randomaccessfile object non-english characters not saved correctly.
specifically, sentence --> "und notenstender libero"
is saved --> "und notenst•nder libero"
where 'e' character not english (the ascii code 917 think).
the code using this:
file = new randomaccessfile(path, "rw"); ... file.seek(file.length()); file.writebytes("the data want");
how can avoid , write correct text?
(ps: know file.writechars, , wondering if there way!)
the main problem might file encoding. should use correct encoding (probably utf-8) , e.g.:
byte[] b = "the data want".getbytes("utf-8"); file.write(b);
note if you're using text viewer/editor check file, depending on 1 you're using might have write utf-8 byte order mark @ beginning of file or tell viewer/editor use utf-8 if can't figure out itself.
Comments
Post a Comment