2016-12-08 85 views
-1

因此以下是我嘗試運行的代碼。我在java只有一週的時間,版主請稍微軟一點。時遇到的使用終端與命令的javac BufferedInputStream.java將FileInputStream包裝成BufferedInputStream錯誤

BufferedInputStream.java:5: error: constructor BufferedInputStream in class BufferedInputStream cannot be applied to given types; 
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("/root/Documents/file")); 
          ^
    required: no arguments 
    found: FileInputStream 
    reason: actual and formal argument lists differ in length 
    BufferedInputStream.java:6: error: cannot find symbol 
     System.out.print(in.read()); 
        ^
    symbol: method read() 
    location: variable in of type BufferedInputStream 
    BufferedInputStream.java:7: error: cannot find symbol 
    in.close(); 
    ^
    symbol: method close() 
    location: variable in of type BufferedInputStream 
    3 errors 

但是使用Netbeans IDE代碼編譯此代碼誤差的

import java.io.*; // its includes input output packages 
class BufferedInputStream{ 
public static void main(String[] args)throws Exception // main method 
{ 
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("/root/Documents/file")); 
// In the above line , I created a BufferedInputStream object(in) and whose constructor takes a File Input Stream 
// (I think of it like tunnel whose one end is attached to app and one end is attached to file and since this is input stream, data can only flow from file to app) 

    System.out.print(in.read()); 
// on oracle's website where every class has a description of its methods and constructors 
// BufferedInputStream object has a method , read() which return next byte , so in.read() should return the first byte 
    in.close(); 
//and its closes the stream 


    } 

} 

LIST工作正常和

output is 98 
// because file has only one character and that is 'b' 

所以,如果代碼正在工作,它應該在(NetBeans和終端)中工作,並且如果代碼是錯誤的,則應該打印出相同的錯誤。 現在我應該信任誰,Netbeans IDE或終端。我處於一個很大的困境

+0

改變你的類的名字'class BufferedInputStream {' –

回答

1

你的類名是BufferedInputStream。這使編譯器感到困惑,因爲它認爲該類正在嘗試創建自己的實例,並且無法找到將FileInputStream作爲參數的構造函數。

改變你的課程名稱。

+0

thnx ...這樣一個愚蠢的錯誤 –