2013-04-26 2 views
0

파일을 읽고 나서 파일을 다시 인쇄하려고합니다. 첫 번째 줄 건너 뛰기.'진술이 아님'은 무엇입니까?

여기 내 코드입니다.

import java.util.Scanner; 
import java.io.File; 
import java.io.*; 
public class cas{ 
public static void main(String[] args) { 
Scanner CL = new Scanner(new File("myBoard.csv")); 
    CL.nextLine; 
    while(CL.hasNext){ 
     String[] tempAdd = CL.nextLine.split(" "); 
     for(int i = 0; i<tempAdd.length; i++) 
      System.out.print(tempAdd[i] + " "); 
     System.out.println(); 
    } 

} 
} 

나는 다음 행으로 포인터를 이동하고 그것으로 아무것도하지 않는 가정이 문을이 오류

cas.java:7: not a statement 
    CL.nextLine; 

을 아닌가요 받고 있어요?

예, 메소드 호출은 컴파일러가 다른 CL.nextLine을 catch하지 않는 이유는 무엇입니까?

+1

'CL.nextLine합니다. –

답변

0

은 다음과 같이 실행할 수 꽵 안 : 당신은 그냥 "CL.nextLine는"당신이 메소드의 이름을 언급 한 작성하는 경우

CL.nextLine(); 

그러나 이것은 아무것도하지 않습니다, 당신은과 방법을 실행해야 "()". 당신은

CL.hasNext(); 
3

과 같은 작업을 수행해야합니다 당신은 변경해야합니다 -

while(CL.hasNext) 

에 -

while(CL.hasNext()){ 

CL.nextLine.split(" ") 

에 -

CL.nextLine().split(" ") 

귀하의 버전은 "구문 오류"로 해석되어야합니다.

0

아래 참조 필요한 경우 코드를 변경했습니다. "()"이 없습니다.

CL.nextLine(); 
    while(CL.hasNext()){ 
     String[] tempAdd = CL.nextLine().split(" "); 
     for(int i = 0; i<tempAdd.length; i++) 
      System.out.print(tempAdd[i] + " "); 
     System.out.println(); 
    } 
0
CL.nextLine; 

이 메소드 호출 아니다. 당신은 다음과 같이 호출한다 :

CL.nextLine(); 
0

자바 컴파일러가 꽵을 생각하는 (난 당신이 CL.nextLine()를 사용한다는 뜻 꽵 메소드를 호출하려고 생각하는) 공공 급 호텔이며 위선적 인 말투 때문에 변수 또는 어떤 것에 그것을 부인하지 않고도 이와 같은 속성을가집니다.이 명령문 (CL.nextLine)은 유효하지 않습니다.

0

당신은 방법에 대해 괄호를 사용해야합니다()`메소드 호출에 대한

scanner.nextLine();        // nextLine() with brackets->() 
while (scanner.hasNext()) {      // hasNext() with brackets->() 
    String[] tempAdd = CL.nextLine().split(" "); // nextLine() with brackets->() 
    for(int i = 0; i<tempAdd.length; i++) 
    System.out.print(tempAdd[i] + " "); 

    System.out.println(); 
} 
0
import java.util.Scanner; 
import java.io.*; 
public class puzzle { 
public static void main(String[] args) { 



    Scanner CL = null; 

    try { 
     CL = new Scanner(new File("F:\\large_10000.txt")); 
    } catch (FileNotFoundException e) { 

     e.printStackTrace(); 
    } 
    CL.nextLine(); 
     while(CL.hasNextLine()){ 
      String[] tempAdd = CL.nextLine().split(" "); 

      for(int i = 0; i<tempAdd.length; i++) 
       System.out.print(tempAdd[i] + " "); 
      System.out.println(); 
      break; 
     } 



} 
}**strong text** 

This code is working fine .just little mistakes. 
+0

'Scanner' 생성자가 Throw하면 nice'NullPointerException'이 발생합니다. 고의적으로 NPE (또는 악화)와 같이 'null'을 신중히 사용하도록 코드하십시오. 던지기위한'main' 메소드를 선언하십시오. –

관련 문제