【发布时间】:2015-02-28 02:42:35
【问题描述】:
我正在尝试读取一个文件并将该文件中的内容写入几个不同的文本文件,但我无法让程序写入任何内容,因为我认为我需要在此处插入一个 nextLine() 但是我不知道在哪里。我是这个网站的新手,也是 java 的新手。请帮忙。
while (readFile.hasNext())
{
m = readFile.nextLine();
p = readFile.nextLine();
double cos = readFile.nextDouble();
double bof = readFile.nextDouble();
profit = bof - cos;
if (profit >= bb)
{
bold.println(m + " " + p + " " + formatter.format(profit));
}
else if (profit >= ss && profit <= bb)
{
solid.println(m + " " + p + " " + formatter.format(profit));
}
else if (profit >= eS && profit <= ss)
{
odd.println(m + " " + p + " " + formatter.format(profit));
}
else
{
flo.println(m + " " + p + " " + formatter.format(profit));
}
}
【问题讨论】:
-
如果什么都没有打印(即没有错误,它只是运行并且什么也不做),那么你的 readFile 是空的或者你的
bold/solid/odd/@987654325 @.println方法不起作用。 -
我确保我的 readFile 不为空,并且我知道我的方法有效,因为我删除了 m 和 p,当它们只涉及双精度时,程序运行完美。
-
等等,程序是真的终止了,还是在等待输入?尝试在
while末尾添加println语句,看看程序是否到达它。 -
没有输入。我正在使用 File 读取文本文档并将文本文档中的信息拆分为其他 4 个文本文档。一段时间后我确实有一个 println 来验证信息是否被移动。
-
System.out.println(readFile.useDelimiter("\u0000").next("[^\u0000]*"));展示?如果您简化方法并将每个变量直接输入 System.out,会打印什么?
标签: java java.util.scanner printwriter