Android UTF-8中的字符串到字节数组的转换大小不稳定地变大了吗?

Android UTF-8中的字符串到字节数组的转换大小不稳定地变大了吗?,android,string,byte,Android,String,Byte,在我的Android应用程序中,我使用文件输出流将数据写入内部存储文件。该过程通常按预期工作,但存储的数据大小有时会明显大于其应有的大小 我设法将问题隔离到代码中的一个特定部分,在那里我尝试通过打印字符串的长度及其字节数组对应项进行调试。尽管使用了UTF-8,但它们似乎有所不同 String dataToWrite = MainActivity.uniqueID + DELIM + MainActivity.rawCalendarData + DELIM + reminderString.toS

在我的Android应用程序中,我使用文件输出流将数据写入内部存储文件。该过程通常按预期工作,但存储的数据大小有时会明显大于其应有的大小

我设法将问题隔离到代码中的一个特定部分,在那里我尝试通过打印字符串的长度及其字节数组对应项进行调试。尽管使用了UTF-8,但它们似乎有所不同

String dataToWrite = MainActivity.uniqueID + DELIM + MainActivity.rawCalendarData + DELIM + reminderString.toString();

/*
Up to this point, the length of raw calendar data is still correct. For some reason, dataToWrite almost doubles in length (not exact double)?
*/

fileOutputStream.write(dataToWrite.getBytes(StandardCharsets.UTF_8));
fileOutputStream.close();
Log.i(MainActivity.LOG_TAG, "Data successfully saved! Length: " + dataToWrite.getBytes(StandardCharsets.UTF_8).length + " bytes (character length: " + dataToWrite.length() + ")");
调试控制台:

I/App: Saving data...
I/App: Data successfully saved! Length: 1107899 bytes (character length: 583611)

有什么想法吗?提前感谢:)

您是否希望字节数等于字符串的长度?它们并不相等,因为UTF-8使用1到4个字节来表示一个字符