APK errors

In Java the letter ə breaks for Excel

FileWriter writes the file with the system table. On Azerbaijani Windows that is often Cp1254. ə is not there, so the letter becomes ?.

Files.writeString writes UTF-8, but it does not put three bytes at the start. Excel can still open that file with the system table. ödəyici then looks like ödÉ™yici.

Put EF BB BF at the start. Do not write Cp1254.

  • Write the CSV with the three bytes above. Excel then sees ə.
  • Do not write new FileWriter("metn.csv"). It picks the table itself and ə is lost.
  • Cp1254 and windows-1254 do not store the letter. Do not pick a table other than UTF-8.
  • Files.writeString does not add a BOM. That is enough for a browser, not for Excel.
  • If the letter in the file is already ?, Java cannot bring it back. Write the text again.
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

byte[] bom = new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF};
byte[] metn = "ad\nAzərbaycan\n".getBytes(StandardCharsets.UTF_8);
byte[] fayl = new byte[bom.length + metn.length];
System.arraycopy(bom, 0, fayl, 0, bom.length);
System.arraycopy(metn, 0, fayl, bom.length, metn.length);
Files.write(Path.of("metn.csv"), fayl);

Related guides