这是我的代码:
fis = openFileInput("MY_FILE");
StringBuffer fileContent = new StringBuffer("");
byte[] buffer = new byte[1024];
while (fis.read(buffer) != -1) {
fileContent.append(new String(buffer));
}
String myVariable = fileContent.toString().trim();
为什么 StringBuffer 需要字节?这究竟是如何工作的?
将 myVariable 设置为 fileContent 时,为什么它的数据后面有多余的空格?(假设 MY_FILE 包含文本 "dad" )
如果没有 trim 方法,它会将变量设置为:dad
在爸爸之后有很多空白。即使文本文件只说“爸爸”