我有一些讀取文本文件的java代碼,將內容添加到一個矢量,然後使用圖形加密器將這些點打印到屏幕上。Java正在讀取舊的輸入文件,而不是新的文件
我有三個pointdata.txt文件,pointdata1.txt,pointdata2.txt和pointdata3.txt。
我遇到的問題是,即使當我將驅動程序中的輸入文件更改爲pointdata1或pointdata2時,它仍然會爲pointdata3運行。我確保代碼中沒有其他地方出現pointdata3。它只出現兩次,但我確定它是一樣的。 我已經檢查過這些文件,它們是不同的。檢查並檢查並檢查路徑名,它們是不同的!
即使我在整個代碼中註釋掉每個System.out.println()
,它仍然會打印所有內容!
這是代碼不再引用文本文件,甚至運行,eclipse只是不斷打印以前添加到視口的內容?
這裏是我的司機代碼:
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文件並查看運行該文件會發生什麼情況。 – 2012-03-05 01:42:57
會從我的驅動程序添加代碼會有幫助嗎? – alice 2012-03-05 01:43:40
您可以給我們提供的所有相關內容都很有幫助。 – 2012-03-05 01:44:38