if-elseブランチで、同じ名前の2つの異なるPrintStreamオブジェクトを宣言しました。ただし、後でPrintStreamオブジェクトを使用すると、コンパイラは「シンボルが見つかりません」と表示します。作成したオブジェクトが表示されないのはなぜですか?オブジェクトは、宣言されたif-elseブランチで機能します。コードは次のとおりです。
System.out.println("Welcome. Would you like to continue a previous adventure, or begin anew?\n(type: new or old)");
status = scan.nextLine();
if(status.equals("new")) {
System.out.println("What do you call yourself?");
name = scan.nextLine();
System.out.println("And what shall be the title of your saga, after you are gone?");
game = scan.nextLine();
System.out.println("Very well. Prepare yourself, for this is the beginning of your end...\n...\n...\nAre you ready?");
status = scan.nextLine();
System.out.println("Not that it matters. Let us begin.");
status = scan.nextLine();
File file = new File(game + ".txt");
PrintStream print = new PrintStream(file);
print.println(name);
old = false;
} else {
System.out.println("So you're still alive? What was the title of your tale?");
game = scan.nextLine();
File file = new File(game + ".txt");
Scanner gscan = new Scanner(file);
String save = "";
while (gscan.hasNextLine()) {
save += gscan.nextLine();
save += "\n";
}
System.out.println(save);
PrintStream print = new PrintStream(file);
print.println(save);
old = true;
name = scan.nextLine();
}
if(old) {
}
print.println("beans");