2016-12-04 75 views
2

我有以下代碼:錯誤:無法找到符號BufferReader

import.java.io.*; 
public class BasheminParkingLot 
{ 
    public static void main(String[]args)throws Exception 
    { 
     Stack parkinglot = new Stack(); 
     Stack alley= new Stack(); 
     File f = new File("bashemin.in"); 
     FileInputStream finstream = new FileInputStream(f); 
     InputStreamReader finreader = new InputStreamReader(finstream); 
     BufferReader finput = new BufferReader(finreader); 
     String line = finput.readLine(); 
     String plate = ""; 
     System.out.println(); 
     System.out.println("The Bashemin Status"); 
     System.out.println(); 

     while(line!=null) 
     { 
      if(line.charAt(0)=='a') 
      { 
       plate = line.substring(1); 
       System.out.println ("car" + plate + " arrived and parked"); 
       parkinglot.Push(plate); 
      } 
     } 

    } 
} 

,並正在錯誤:

BasheminParkingLot.java:13:錯誤:無法找到符號 BufferReader finput =新BufferReader (finreader); ^

我想知道是否有人可以幫助我調試?謝謝!

+0

請接受的答案,如果它爲你工作。接受和投票將激勵人們回答你的問題。 –

回答

0

這不應該是BufferReader。它應該是BufferedReader

下面的代碼將工作:

 
import java.io.*; 

class Stack { 
    int x; 

    void Push(String value) { 
     // DO SOMETHING 
    } 
} 

public class BasheminParkingLot 
{ 
    public static void main(String[]args)throws IOException 
    { 
     Stack parkinglot = new Stack(); 
     Stack alley= new Stack(); 
     File f = new File("bashemin.in"); 
     FileInputStream finstream = new FileInputStream(f); 
     InputStreamReader finreader = new InputStreamReader(finstream); 
     BufferedReader finput = new BufferedReader(finreader); 
     String line = finput.readLine(); 
     String plate = ""; 
     System.out.println(); 
     System.out.println("The Bashemin Status"); 
     System.out.println(); 

     while(line!=null) 
     { 
      if(line.charAt(0)=='a') 
      { 
       plate = line.substring(1); 
       System.out.println ("car" + plate + " arrived and parked"); 
       parkinglot.Push(plate); 
      } 
     } 

    } 
}