Java.io.BufferedInputStream.available()方法实例
2017-12-26 13:19
302 查看
java.io.BufferedInputStream.available() 方法返回从输入流中读取不受阻塞,输入流方法的下一次调用的剩余字节数。
java.io.BufferedInputStream.available() 方法返回从输入流中读取不受阻塞,输入流方法的下一次调用的剩余字节数。
声明
以下是java.io.BufferedInputStream.available()方法的声明public int available()
返回值
此方法返回的字节数保持从此输入流中读取而不阻塞。异常
IOException -- -- 如果发生I/O错误.public class BufferedInputStreamDemo { public static void main(String[] args) throws Exception { InputStream inStream = null; BufferedInputStream bis = null; try{ // open input stream test.txt for reading purpose. inStream = new FileInputStream("c:/test.txt"); // input stream is converted to buffered input stream bis = new BufferedInputStream(inStream); // read until a single byte is available while( bis.available() > 0 ) { // get the number of bytes available Integer nBytes = bis.available(); System.out.println("Available bytes = " + nBytes ); // read next available character char ch = (char)bis.read(); // print the read character. System.out.println("The character read = " + ch ); } }catch(Exception e){ e.printStackTrace(); }finally{ // releases any system resources associated with the stream if(inStream!=null) inStream.close(); if(bis!=null) bis.close(); } } }
相关文章推荐
- java.io.BufferedInputStream 源码分析
- java io FilterInputStream BufferedInputStream
- 我的Java开发学习之旅------>Java使用ObjectOutputStream和ObjectInputStream序列号对象报java.io.EOFException异常的解决方法
- java.io.Reader.read(char[] cbuf)方法实例
- Java.io.File.mkdirs()方法实例
- Java网络编程中inputStream.available()的使用方法
- 流 JAVA IO 基本小结 通过一行常见的代码讨论:new BufferedReader(new InputStreamReader(System.in))
- java io系列12之 BufferedInputStream(缓冲输入流)的认知、源码和示例
- java io系列12之 BufferedInputStream(缓冲输入流)的认知、源码和示例
- Java BufferedInputStream与BufferedOutputStream 入门版实例解析【文件操作】
- java.io.ByteArrayInputStream的mark方法
- 流 JAVA IO 基本小结 通过一行常见的代码讨论:new BufferedReader(new InputStreamReader(System.in))
- Java-IO之BufferedInputStream(缓冲输入流)
- Java IO:BufferedInputStream使用详解及源码分析
- java.io.Reader.read()方法实例
- Java-IO之BufferedInputStream(缓冲输入流)
- java.io.IOException: BufferedInputStream is closed
- Java网络编程中inputStream.available()的使用方法
- 黑马程序员 java基础IO BufferedInputStream
- java.io.File.listFiles(FileFilter filter)方法实例