2017-12-19 34 views
-1

내가 파일 라이터를 사용하여 파일을 작성하기 위해 노력하고있어 널 (null)이지만 값은 null입니다 :출력 파일의 값은 (0킬로바이트)

FileReader inCorpus2=new FileReader("output2.txt"); 
     FileWriter outCorpus2=new FileWriter("Doc2(THE WANTED FILE).txt"); 
     Scanner sc2=new Scanner(inCorpus2); 
     try{ 
      while(sc2.hasNextLine()){ 
       String tempLine=sc2.nextLine(); 
       Scanner sc3=new Scanner(tempLine); 
     while(sc3.hasNext()){ 
      String temp=sc3.next(); 
      for(int i=0;i<UC.length;i++){ 
       for(int j=0;j<temp.length();j++){ 
       if(temp.charAt(j)==UC[i])temp=removeChar(temp,j); 
       } 
      } 

을 그리고이 오류 마사지입니다 :

Exception in thread "main" java.util.NoSuchElementException: No line found 
at java.util.Scanner.nextLine(Unknown Source) 
at aya.SecondFilePreproc.main(SecondFilePreproc.java:25) 

나는 내가 분명했으면 좋겠어. 최선을 다 했어. 제발 도와 줘.

+1

당신은'hasNext를 사용하여 문제를 해결할 수 있습니다()'대신 hasNextLine'의()'. [이 답변] (https://stackoverflow.com/a/31993534/4039840)을 참조하십시오. 코드에서 –

+2

브리핑을 확인하면 정상적으로 실행됩니다. 문제를 시연 할 MCVE를 제공해야합니다 –

+0

@TuyenNguyen 같은 코드가 다른 파일에서 작동했습니다 .. –

답변

-1

도움이 필요하시면 전체 코드를 확인해야합니다. 그냥 몇 가지 예외를 추가했습니다.

import java.io.*; 
import java.util.Scanner; 
public static String removeChar(String x,int y){ 
return "something"; 
} 
public class SomeClass { 

public static void main(String[] args) throws FileNotFoundException, IOException { 
     try(FileReader inCorpus2=new FileReader("output2.txt"); 
      FileWriter outCorpus2=new FileWriter("Doc2(THE WANTED FILE).txt"); 
      Scanner sc2=new Scanner(inCorpus2) 
       ){ 
      while(sc2.hasNextLine()){ 
       String tempLine=sc2.nextLine(); 
       Scanner sc3=new Scanner(tempLine); 
     while(sc3.hasNext()){ 
      String temp=sc3.next();  
      //just a guess what is UC 
      //char UC[]={'A','B','C'}; 
     } 
      for(int i=0;i<UC.length;i++){ 
       for(int j=0;j<temp.length();j++){ 
       if(temp.charAt(j)==UC[i])temp=removeChar(temp,j); 
       } 
      } 
     } 
    } 
    } 
}