我有几个类在开始时执行一些功能,它们写入 csis.txt。之后我会弹出一个窗口来显示 csis.txt 中的内容,并进行格式化。但是,它的格式不正确。这是我所拥有的:
import java.io.*;
import java.awt.*;
import java.util.Scanner;
public class Driver extends Canvas {
public Driver(){
setSize(200, 200);
setBackground(Color.white);
}
public static void main(String[] args) throws IOException {
PrintWriter pw = new PrintWriter(new FileWriter("csis.txt"));
MFQ mfq = new MFQ(pw);
mfq.getJobs();
mfq.outputHeader();
mfq.runSimulation();
mfq.outStats();
pw.close();
Driver GP = new Driver();
Frame aFrame = new Frame();
aFrame.setSize(1000, 1000);
aFrame.add(GP);
aFrame.setVisible(true);
}
public void paint(Graphics g) {
try {
Scanner fileScan = new Scanner(new File("csis.txt"));
String s = fileScan.nextLine();
for (int i = 20; fileScan.hasNext(); i += 20) {
g.drawString(fileScan.nextLine(), 0, i);
}
}
catch (IOException e) {
System.err.println("Caught IOException: " + e.getMessage());
}
}
}
csis.txt:
csis.txt 的旁边和图形窗口格式不正确: