Java: Is the value of a String's characters (in bytes) constant?
===

<b>TL;DR</b>: In Java, will casting a character obtained from a String via the `charAt` method to a byte always yield the same value?<br>
<br>
I am reading files which are encoded with arbitrary (unknown to us) character encodings. I need to parse these files and look for certain words, e.g. "TAG". I placed certain restrictions on the file contents, such as "when looking for a tag, the bytes for "TAG" must be the same as their ASCII representation".<br>
<br>
For example, suppose I have the following file:<br>
`0x00 0x11 0x22 0x33 0x54 0x41 0x47 0x77 0x88 0x99 0xaa 0xbb`<br>
Since the ASCII values for T, A and G are respectively `0x54`, `0x41` and `0x47`, I can find "TAG" in the file by parsing the bytes themselves.<br>
`0x00 0x11 0x22 0x33 `<b>`0x54 0x41 0x47`</b>` 0x77 0x88 0x99 0xaa 0xbb`<br>
<br>
However, I need to hard-code the value of the bytes I am looking for. To do this, I call `String`'s `charAt(int i)` method and cast the char to a byte.<br>
<br>
Here is, for example, how I would verify an arbitrary byte (called `b`) for the byte representation of 'T':<br>
`String tag = "TAG";`<br>
`char t = tag.charAt(0);`<br>
`if ((byte)t == b){`<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`//magic goes here, such as comparing the 'A' and the 'G'`<br>
`}`<br>
<i>Note: the code is not actually like that, and the verification algorithm is much more elegant.</i><br>
<br>
This works fine on my local machine. However, this will be run on machines which may contain very strange encodings. What worries me is whether casting a character obtained with `charAt` to a byte might yield a different value depending on the machine. I know that Java always encodes `char`s with the UTF-16 character encoding, but I am worried that when converting from a String to a character and then to a byte might yield strange results.<br>
<br>
So, in short, will casting a character obtained from a String via the `charAt` method to a byte always yield the same value? Or will it depend on an external factor?<br>
<br>
Thanks for your help!<br>
<br>
<i><b>Note</b>: I cannot hard-code the bytes themselves (in, for example, a byte array) since they can be very very long and may be changed very often in the future.</i>