I tried the code below:
public static void main(String[] args) throws IOException {
String s = "NETWORK";
try (
FileOutputStream fos = new FileOutputStream("d:/endian.txt");
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF_16BE");) {
osw.write(s);
osw.flush();
}
}
after starting, I get a file that contains the following chain: NETWORK; the size of the received file is 14 bytes (7 characters * 2 bytes). note the spaces between the characters of the chain. when I change the encoding with: UTF_16LE, I get a file size of 14 bytes, which contains the following line: NETWORK. no spaces between characters !!. I expect the line as follows: NETWOR K. I used notepad to open the file. Can anyone explain this behavior?
source
share