在 JAVA 中,我想读取最大为 1MB 大小的 .log 文件的完整内容,我需要将其存储在 StringBuilder 中
我尝试使用此代码,但给出异常 STACKERRORFLOW。
String fileName = "C://test//.log";
File testfile = new File(fileName);
int ch;
StringBuilder strcontent = new StringBuilder();
try
{
FileInputStream fis = new FileInputStream(testfile);
while((ch = fis.read()) != -1)
strcontent.append((char)ch);
fis.close();
}
System.out.println(strcontent.toString());
它会出现什么问题。