It depends on how you write the data to file and your requirement.
For the standard ASCII and UT8 encodings (which will cover english and similar other charsets), string length and file byte length will match, as one character takes only byte in file.
For Unicode encodings (like japanese chars), as you said string length and file byte length will not match as one character will take two bytes.
Below is the code for both the encodings, you can use as per your requirement.