BufferedInputStream class in java
java.io.BufferedInputStream is a class in java programming language. Inside of this class exists 8 public methods. Declaration of this class as follows.
public class java.io.BufferedInputStream
extends java.io.FilterInputStream
BufferedInputStream public method
There are following useful methods which is define the inside of java.io.BufferedInputStream class.
Method | Description |
---|---|
int available() | its returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. |
void close() | it closes this input stream and releases any system resources associated with the stream. |
void mark(int) | it see the general contract of the mark method of InputStream. |
boolean markSupported() | it tests if this input stream supports the mark and reset methods. |
int read(byte[], int, int) | it reads bytes from this byte-input stream into the specified byte array, starting at the given offset. |
int read() | its See the general contract of the read method of InputStream. |
void reset() | it see the general contract of the reset method of InputStream. |
long skip(long) | it see the general contract of the skip method of InputStream. |
This reference is belong to javadoc
Public Constructors
public java.io.BufferedInputStream(java.io.InputStream)
public java.io.BufferedInputStream(java.io.InputStream,int)
import java.io.FileInputStream;
import java.io.BufferedInputStream;
public class Example
{
public static void main(String args[])
{
try
{
// data.text is file which exists in current directory
FileInputStream fileInStream =
new FileInputStream("data.txt");
BufferedInputStream bufferedInStream =
new BufferedInputStream(fileInStream);
int info;
// Display file text
while ((info = bufferedInStream.read()) != -1)
{
// Display character record
System.out.print((char) info);
}
// close BufferedInputStream
bufferedInStream.close();
// close FileInputStream
fileInStream.close();
}
catch (Exception e)
{
// Handling file missing exception
System.out.println(e);
}
}
}

Hello, Programmer
java.io.BufferedInputStream other method example
import java.io.FileInputStream;
import java.io.BufferedInputStream;
public class Example
{
public static void main(String args[])
{
try
{
// data.text is file which exists in current directory
FileInputStream fileInStream =
new FileInputStream("data.txt");
BufferedInputStream x =
new BufferedInputStream(fileInStream);
int info = x.available();
System.out.println("available : "+info);
x.mark(2);
if(x.markSupported())
{
System.out.println("markSupported : Yes");
}
else
{
System.out.println("markSupported : No");
}
x.reset();
x.skip(4);
// Display file text
while ((info = x.read()) != -1)
{
// Display character record
System.out.print((char) info);
}
// close BufferedInputStream
x.close();
// close FileInputStream
fileInStream.close();
System.out.println("\navailable : "+info);
}
catch (Exception e)
{
// Handling file missing exception
System.out.println(e);
}
}
}
available : 17
markSupported : Yes
o, Programmer
available : -1
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment