2012-03-05 2 views
0

텍스트 파일을 읽고, 내용을 벡터에 추가 한 다음, 그래프 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(); 
    } 
} 
+1

정확히 알고 싶으면 코드를 확인해야합니다. 나는 당신이 그것에 디버거를 실행하는 것이 좋습니다. 또한 프로젝트를 컴파일하고 있습니까? JAR 파일을 만들고 그 파일을 실행하면 어떻게 될지 볼 수 있습니다. –

+0

내 드라이버 코드가 도움이 될까요? – alice

+0

당신이 우리에게 줄 수있는 모든 것이 도움이됩니다. –

답변

1

것 같습니다 : 여기

내 드라이버에서 코드입니다. 나는 당신이 printlns를 주석 처리했다고 말했을 때 이것을 모으고 있지만 출력물은 여전히 ​​표시 중입니다.

몇 가지 확인 : 메뉴에서

  • 프로젝트>이 빌드가 자동으로가 설정되어 있는지 확인하십시오. 설정되어 있지 않으면 설정하고 문제를 해결해야합니다.
  • 소스를 변경할 때 클래스 파일의 타임 스탬프가 변경되는지 확인하십시오. 그렇지 않은 경우, Eclipse는 어떤 이유로 다시 컴파일하지 않습니다. bin 폴더 아래에 클래스 파일이있을 수 있습니다 (Eclipse 프로젝트 기본값을 사용하는 경우).
  • 타임 스탬프가 오래된 경우 Eclipse 외부에서 bin 폴더를 제거하십시오. 그런 다음 프로젝트를 마우스 오른쪽 버튼으로 클릭하고 새로 고침을 선택하십시오. 마지막으로 프로젝트>을 선택하십시오. 이렇게하면 코드가 새 클래스 파일로 다시 컴파일됩니다.
+0

예, 10 번 중 8 번 문제가 Eclipse입니다. IDEA로 업그레이드하고보다 쉽게 ​​생활하십시오. – Synesso

+0

ok .. 당신이 말한 모든 것을 시도해 보았습니다. 오래된 .CLASS 파일을 실행 중이었기 때문에 빈을 지 웠습니다. 그리고 지금은 코드를 실행할 때마다 새 파일을 만들고 있습니다.하지만 여전히 이전 코드를 실행 중입니다! 이것도 어떻게 가능합니까 ?? – alice

+0

내가 메모장에서 만든 .CLASS 파일을 열면 wingdings가 가득 찼습니다. – alice

관련 문제