我试图创建一个缓冲的读者,通过聊天来发表演讲,目的是让长篇大论变得更容易。我有一个缓冲的读者听到,它的大部分工作,但它只读最后一行,其他一切都很好。我在密码里哪里出错了?这里的参考是:(为了澄清,“茄子时间”是延迟的布尔值)
静态文件华夫饼=新文件(Minecraft.getMinecraftDir(),"speech.txt");
public static void speechedo(String args)
{
if(waffles.exists())
{
@SuppressWarnings("resource")
BufferedReader read = null;
try {
read = new BufferedReader(new FileReader(waffles));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String notataco;
if (eggtime){
try {
for(int i = 0; (notataco = read.readLine()) != null; i++)
{
speechmakerchat = notataco;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}else{
return;}
}发布于 2012-09-19 00:25:38
排在队伍里
speechmakerchat = notataco;您将用最后一行替换speechmakerchat的内容,放弃以前读取的值。您需要将新数据与旧数据连接起来:
speechmakerchat += notataco;顺便说一句你有..。有趣..。变量的命名约定。
发布于 2012-09-19 00:38:54
我为“我的世界”缓冲的读者只读最后一行
不,你的缓冲阅读器能读到每一行。然而,除了最后一行之外,你正在抛弃所有的一切。
另外,您的异常处理也很糟糕。您不应该允许方法在IOException构造BufferedReader之后继续。大多数情况下,捕获块位于错误的位置:它们应该是所有的主要代码。
https://stackoverflow.com/questions/12486910
复制相似问题