将打印流输入到文本文件



//我在文本文件中搜索Int,在控制台上显示该Int,创建一个文本文件来打印该Int。我得到的是这个,而不是Int:

java.util.Scanner[derminaters=\p{javaWhitespace}+][position=666][match valid=true][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive后缀=][negative后缀=][NaN字符串=\Q�\E] [无穷大字符串=\Q∞\E]1920:,
public static void findName(Scanner input, String name) throws FileNotFoundException {
boolean find = false;
while (find == false && input.hasNext()) {
String search = input.next();
if (search.startsWith(name) && search.endsWith(name)) {
PrintStream output = new PrintStream(new File(name + ".txt"));
output.println(name + ",");
System.out.println("1920: " + input.nextInt());
output.println("1920: " + input + ","); // need help here. HOW DO I GET THIS TO PRINT THE SAME INT, NOT GO TO THE SECOND INT?
System.out.println("1930: " + input.nextInt());
output.println("1930: " + input + ",");
System.out.println("1940: " + input.nextInt());
output.println("1940: " + input + ",");
System.out.println("1950: " + input.nextInt());
output.println("1950: " + input + ",");
System.out.println("1960: " + input.nextInt());
output.println("1960: " + input + ",");
System.out.println("1970: " + input.nextInt());
output.println("1970: " + input + ",");
System.out.println("1980: " + input.nextInt());
output.println("1980: " + input + ",");
System.out.println("1990: " + input.nextInt());
output.println("1990: " + input + ",");
System.out.println("2000: " + input.nextInt());
output.println("2000: " + input);
find = true;
}
}
if (find == false) {
System.out.println("name not found.");

您正在将输入对象而不是int打印到文件中。

试试这个:

int next = input.nextInt()
System.out.println("1920: " + next );
output.println("1920: " + next + ",");
... 

希望这能帮助

相关内容

  • 没有找到相关文章

最新更新