java - how BufferedInputStream.available works? -


        fileinputstream in=new fileinputstream("dd.txt");         bufferedinputstream bufi= new bufferedinputstream(in);         system.out.println(bufi.available());         int half =bufi.available()/2;         bufi.skip(half);         system.out.println(bufi.available()); 

output:

7

4

in "dd.txt" there 1234567

but why bufi can skip before use bufi.read(),i mean when data sent input stream?

it works adding number of bytes buffered, possibly zero, value returned available() method of wrapped stream. in case wrapped stream fileinputstream, available() method returns, arguably incorrectly, number of bytes remaining read in file.

there no reason why skip() should not possible prior read(). data never 'sent t imoitbstream'. read by input stream.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -