我正在写一个文件,想要控制台输出,
// TODO Create a game engine and call the runGame() method
public static void main(String[] args) throws Exception {
NewGame myGame = new TheGame().new NewGame();
myGame.runGame();
PrintStream out = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);
}
Run Code Online (Sandbox Code Playgroud)
这给了我控制台输出,但它抛出以下异常:
java.io.FileNotFoundException: TheGame.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at game.main(TheGame.java:512)
Run Code Online (Sandbox Code Playgroud)
该文件确实存在.
有人可以帮我解决下面发布的错误吗?该程序运行,但在调用显示捐赠时,我收到关于我的主要的错误.我怎么能解决这个问题呢?是否与语法错误有关?这是我第一次使用数组,所以我欢迎有关良好习惯的反馈.谢谢!
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at donations.processDonations(donations.java:78)
at donations.main(donations.java:33)
import java.util.Scanner; //needed for input
public class donations {
static double[] cashDonations = new double[6]; // stores the cash donations
// from 6 sites
static double[] lbsFood = new double[6]; // stores the pounds of food
// donated from 6 sites
static String[] siteName = new String[6]; // stores the names of the 6 sites
static String bestSiteCash = " "; // stores the site name with the highest …Run Code Online (Sandbox Code Playgroud)