无法打开文本文件Java Eclipse
我正在尝试使用文本文件测试一个程序。我在文本文件方面没有太多经验,所以我在尝试打开文本文件时遇到了一些问题。我写的测试人员写在下面:
public class TestGetPlanet {
public static void main(String[] args) {
checkGetPlanet();
}
private static void checkEquals(double d1, double d2, String label) {
if (d1 == d2) {
System.out.println("PASS: " + label + ": " + d1 + " equal to " + d2);
} else {
System.out.println("FAIL: " + label + ": " + d1 + " not equal to " + d2);
}
}
private static void checkStringEquals(String s1, String s2, String label) {
if (s1.equals(s2)) {
System.out.println("PASS: " + label + ": " + s1 + " equal to " + s2);
} else {
System.out.println("FAIL: " + label + ": " + s1 + " not equal to " + s2);
}
}
private static void checkGetPlanet() {
System.out.println("Checking getPlanet...");
In in = new In("data/planets.txt");
in.readInt();
in.readDouble();
Planet p = Simulator.getPlanet(in);
checkEquals(p.x, 1.496e11, "x");
checkEquals(p.y, 0.0, "y");
checkEquals(p.xVelocity, 0.0, "xVelocity");
checkEquals(p.yVelocity, 29800.0, "yVelocity");
checkEquals(p.xAccel, 0.0, "xAccel");
checkEquals(p.yAccel, 0.0, "yAccel");
checkStringEquals(p.img, "earth.gif", "image");
}
}
我想打开的文本文件(planets.txt
)是:
1.4960e+11 0.0000e+00 0.0000e+00 2.9800e+04 5.9740e+24 earth.gif
2.2790e+11 0.0000e+00 0.0000e+00 2.4100e+04 6.4190e+23 mars.gif
5.7900e+10 0.0000e+00 0.0000e+00 4.7900e+04 3.3020e+23 mercury.gif
0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 1.9890e+30 sun.gif
1.0820e+11 0.0000e+00 0.0000e+00 3.5000e+04 4.8690e+24 venus.gif
[!] Your program should not read this line, as all 5 planets were already listed
and there is no further information to be specified. So you can put comments here.
This file contains the inner 4 planets of our solar system and the sun.
共 (0) 个答案