2017-12-19 20 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

あなたは代わりに 'hasNextLine()'の 'のhasNext()を'使用して、問題を解決する可能性があります。 [この回答](https://stackoverflow.com/a/31993534/4039840)を参照してください。コード上で –

+2

の略語がチェックされ、正常に動作します。 –

+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); 
       } 
      } 
     } 
    } 
    } 
} 
関連する問題