我已经查看了一些如何在 Java 中写入文件的示例,我认为我做得对......显然不是。这里有什么问题,它甚至没有创建要写入的文件。没有错误,只是没有写入文件。
File inputFile = new File("pa2Data.txt");
File outputFile = new File("pa2output.txt");
Scanner fileIn = new Scanner(inputFile);
BufferedWriter fout = new BufferedWriter(new FileWriter(outputFile));
while(fileIn.hasNext()){
String theLine = readFile(fileIn);
fout.write("Infix expression: " + theLine + '\n');
postfixExpression = infixToPostFix(theLine);
String op = postfixExpression.toString();
fout.write("Postfix Expression: " + op + '\n');
theLine = readFile(fileIn);
StringTokenizer st = new StringTokenizer(theLine);
for(int i = 0; i < theValues.length; i++)
theValues[i] = Integer.parseInt(st.nextToken());
int answer = postfixEval(postfixExpression, theValues);
fout.write("Answer: " + answer + '\n' + '\n');
}
fileIn.close();
fout.close();
}//end main