텍스트 파일을 읽고, 내용을 벡터에 추가 한 다음, 그래프 windower를 사용하여 화면에 이러한 점을 인쇄하는 Java 코드가 있습니다.자바가 새로운 것들이 아닌 오래된 입력 파일을 읽습니다.
나는 pointdata1.txt 파일, pointdata2.txt 및 pointdata3.txt 파일을 가지고 있습니다.
내가 겪고있는 문제는 드라이버에서 입력 파일을 pointdata1 또는 pointdata2로 변경하더라도 pointdata3에서 실행됩니다. 나는 코드 내의 pointdata3이 어디에도 존재하지 않도록 보장했다. 그것은 두 번 나타납니다,하지만 나는 그것이 동일하다는 것을 확실히했습니다. 파일 자체를 검사했는데 다른 파일입니다. 확인하고 경로 이름을 확인하고 확인했습니다.
전체 코드에서 System.out.println()
을 모두 주석 처리하더라도 모든 것을 여전히 인쇄합니다!
코드가 더 이상 텍스트 파일을 참조하지 않거나 실행 중이면 일식이 이전에 뷰포트에 추가 된 내용을 계속 인쇄합니까? 이클립스 클래스 파일의 이전 버전을 실행하는 것처럼
import java.util.*;
public class PointDriver {
private PointField pointfield;
// testing
public void doAllTests() throws Exception{
this.test1();
this.test2();
}
// Display all points in the file
public void test1() throws Exception{
SimpleIO sIO = new SimpleIO();
System.out.println("Contents of Point File: ");
sIO.displayFile("pointdata1.txt");
//sIO.displayFile("pointdata2.txt");
//sIO.displayFile("pointdata3.txt");
System.out.println();
}
// Load points from a file into a vector and echo them back to the screen
// This uses the StringTokenizer to split the lines into two Strings, then
// uses the Point class to assign the two Strings to x,y double variables
// which form Points. Within the same loop, the points are also displayed
// in a window using the Graph Window class. Maximum x and y values are used
// to determine the dimensions of the GraphWindow, adding 10 units to each
// value to provide a border.
public void test2() throws Exception{
System.out.println("Contents of Point File: ");
System.out.println();
System.out.println("Points are Displayed in a Graph Window");
System.out.println();
Vector lines;
lines = pointfield.getlines("pointdata1.txt");
//lines = pointfield.getlines("pointdata2.txt");
//lines = pointfield.getlines("pointdata3.txt");
Iterator IT;
IT = lines.iterator();
Vector v;
v = new Vector();
double maxX, maxY;
PointField pointfield;
pointfield = new PointField();
GraphWindow gw;
gw = new GraphWindow();
while (IT.hasNext()) {
StringTokenizer st;
String ID = (String)IT.next();
st = new StringTokenizer(ID);
double x = Double.parseDouble(st.nextToken());
double y = Double.parseDouble(st.nextToken());
Point p;
p = new Point(x,y);
v.addElement(p);
int i = v.size();
System.out.println("Point ID: " +i+ " X: "+x+", Y: "+y);
gw.plotPoint(x, y);
}
this.pointfield = new PointField(v);
maxX = this.pointfield.findMaxXPoint();
maxY = this.pointfield.findMaxYPoint();
int width = (int)maxX + 10;
int height = (int)maxY + 10;
gw.setMap(width, height);
}
// Short main method to kick of all tests sequence in doAllTests method
public static void main(String[] args) throws Exception {
PointFieldDriver pfd;
pfd = new PointFieldDriver();
pfd.doAllTests();
}
}
정확히 알고 싶으면 코드를 확인해야합니다. 나는 당신이 그것에 디버거를 실행하는 것이 좋습니다. 또한 프로젝트를 컴파일하고 있습니까? JAR 파일을 만들고 그 파일을 실행하면 어떻게 될지 볼 수 있습니다. –
내 드라이버 코드가 도움이 될까요? – alice
당신이 우리에게 줄 수있는 모든 것이 도움이됩니다. –