2013-09-27 168 views
-3
File inputTXT = new File (fileName); 

    try{ 
    Scanner in = new Scanner(inputTXT); 
    }catch(FileNotFoundException e){ 
     System.out.println(""); 
    } 
     while(in.hasNext()){ 
      String line = in.nextLine(); 

它說在無法解決。我該如何解決這個問題?掃描儀無法解析

我試着忽略try catch塊,但該文件的掃描儀必須是在try catch塊

+1

您是否可能缺少'import'語句? –

+0

向我們展示整個代碼,並彈出錯誤消息。 – Prateek

+1

不要只是吞下異常;至少打印出來。否則,你永遠不會知道它是否拋出錯誤。 – iamnotmaynard

回答

0

在你的代碼有關於可變scope.You問題定義在try catch塊in變量,然後你在while循環中使用它。它應該如下所示:

File inputTXT = new File (fileName); 
    Scanner in=null; 
    try{ 
    in = new Scanner(inputTXT); 
    }catch(FileNotFoundException e){ 
     System.out.println(""); 
    } 
     while(in.hasNext()){ 
      String line = in.nextLine();