{"id":89813,"date":"2024-05-02T18:00:15","date_gmt":"2024-05-02T12:30:15","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=89813"},"modified":"2024-05-02T18:39:01","modified_gmt":"2024-05-02T13:09:01","slug":"java-bufferedinputstream-class","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/","title":{"rendered":"Java BufferedInputStream Class with Examples"},"content":{"rendered":"<p>Another input stream gains functionality with the Java.io.BufferedInputStream class, which supports the mark and reset methods in addition to buffering input.<\/p>\n<h2>Explanation<\/h2>\n<p>When an input stream is wrapped (bufferized) into a buffered stream, it becomes a BufferedInputStream in Java, which is a concrete subclass of FilterInputStream and improves the speed and efficiency of read operations on the stream.<\/p>\n<p><strong>Note<\/strong><\/p>\n<ul>\n<li>When bytes in the stream were read or skipped, the internal buffer automatically filled up, many bytes at a time, from the contained input stream.<\/li>\n<li>An internal buffer array is created during the creation of a BufferedInputStream.<\/li>\n<\/ul>\n<h3>Constructor<\/h3>\n<ul>\n<li>BufferedInputStream(InputStream in)<br \/>\nMakes a BufferedInputStream and stores the input stream as its argument for later usage.<\/li>\n<li>BufferedInputStream(InputStream in, int size)<br \/>\nSaves its argument, the input stream in, for later usage and creates a BufferedInputStream with the given buffer size.<\/li>\n<\/ul>\n<h3>Method<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0<strong> \u00a0 \u00a0 Method<\/strong><\/span><\/td>\n<td><strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">int available()<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The number of bytes from the input stream that can be used without being blocked is returned by this method<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">void close()<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Closes the current input stream and frees up any related system resources.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">void mark(int readlimit)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Indicates where you are right now in this input stream.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">boolean markSupported()<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Checks whether the mark and reset methods are supported by this input stream<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">int read()\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Opens the input stream and reads the subsequent byte of data<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">void reset()\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This stream back to its original position when this input stream&#8217;s mark method was last called.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">long skip(long n)\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This input stream&#8217;s n bytes of data are ignored and discarded.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>int available()<\/h4>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public int available()\r\n              throws IOException<\/pre>\n<h4>void close()<\/h4>\n<p><strong><strong>Syntax:<\/strong><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public void close()\r\n           throws IOException<\/pre>\n<h4>void mark(int readlimit)<\/h4>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public void mark(int readlimit)<\/pre>\n<p>boolean markSupported()<br \/>\n.<br \/>\n<strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public boolean markSupported()<\/pre>\n<h4>int read()<\/h4>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public int read()\r\n         throws IOException<\/pre>\n<h4>void reset()<\/h4>\n<p><strong><strong>Syntax:<\/strong><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public void reset()\r\n           throws IOException<\/pre>\n<h4>long skip(long n) .<\/h4>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public long skip(long n)\r\n          throws IOException<\/pre>\n<h4>Declaration:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public class BufferedInputStream extends<\/pre>\n<h4>Example<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import java.io.BufferedInputStream;\r\nimport java.io.FileInputStream;\r\npublic class TechVidvan{\r\npublic static void main(String[] args)\r\n{\r\n try\r\n {\r\n   FileInputStream fi= new FileInputStream(\"D:\\\\myfiles.txt\");\r\n  \r\n   BufferedInputStream b= new BufferedInputStream(fi);\r\n \r\n   System.out.println(\"Available bytes at  beginning: \" + b.available());  \r\n \r\n   b.read();\r\n   b.read();\r\n   b.read();\r\n \r\n   System.out.println(\"Available bytes at  end: \" + b.available());\r\n    b.close();  \r\n}\r\ncatch(Exception e)\r\n {\r\n   System.out.println(e);\r\n }\r\n }\r\n}<\/pre>\n<p><strong>Output<\/strong><br \/>\nAvailable bytes at beginning: 25<br \/>\nAvailable bytes at end: 22<\/p>\n<h4>Example<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import java.io.BufferedInputStream;\r\nimport java.io.FileInputStream;\r\n\r\npublic class TechVidvan{\r\npublic static void main(String[] args)\r\n{\r\n try\r\n {\r\n   FileInputStream f= new FileInputStream(\"D:\\\\myfile.txt\");\r\n  \r\n   BufferedInputStream bis = new BufferedInputStream(f);\r\n    bis.skip(5);\r\n\r\n   System.out.println(\"Input stream after skipping first 5 bytes:\");\r\n\r\n   int i = 0;\r\n   while ((i = bis.read()) != -1)\r\n {\r\n    System.out.print((char) i);\r\n   }\r\n    bis.close();  \r\n}\r\ncatch(Exception e)\r\n {\r\n   System.out.println(e);\r\n }\r\n }\r\n}<\/pre>\n<p><strong>myfile.txt<br \/>\n<\/strong>TechVidvan<\/p>\n<p><strong>Output<\/strong><br \/>\nInput stream after skipping first 5 bytes:<br \/>\nidvan<\/p>\n<h4>Example<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import java.io.*;  \r\npublic class TechVidvan{    \r\n public static void main(String args[])\r\n{    \r\n  try\r\n{    \r\n    FileInputStream fin=new FileInputStream(\"D:\\\\testout.txt\");    \r\n    BufferedInputStream bin=new BufferedInputStream(fin);    \r\n    int i;    \r\n    while((i=bin.read())!=-1)\r\n{    \r\n     System.out.print((char)i);    \r\n    }    \r\n    bin.close();    \r\n    fin.close();    \r\n  }\r\ncatch(Exception e)\r\n\r\n{\r\nSystem.out.println(e);\r\n}    \r\n }    \r\n}<\/pre>\n<p><strong>testout.txt<\/strong><br \/>\nI am Learning java programming course in TechVidvan.<br \/>\n<strong>Output<\/strong><br \/>\nI am Learning java programming course in TechVidvan.<\/p>\n<h3>Conclusion<\/h3>\n<p>The superclass of Input operations, the input stream is utilized to read user input from a file, keyboard, etc. It is employed to depict a byte-stream input. It is descended from Reader, an abstract class. In order to reduce the amount of Input operations and facilitate quicker and more efficient reading, it keeps an internal character buffer full.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Another input stream gains functionality with the Java.io.BufferedInputStream class, which supports the mark and reset methods in addition to buffering input. Explanation When an input stream is wrapped (bufferized) into a buffered stream, it&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":447204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[5501,5499,5500,296,310,311,5641,299,263,250],"class_list":["post-89813","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-bufferedinputstream","tag-bufferedinputstream-class","tag-bufferedinputstream-class-in-java","tag-java","tag-java-bufferedinputstream","tag-java-bufferedinputstream-class","tag-java-bufferedinputstream-class-with-examples","tag-java-tutorial","tag-java-tutorial-for-beginners","tag-learn-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java BufferedInputStream Class with Examples - TechVidvan<\/title>\n<meta name=\"description\" content=\"When an input stream is wrapped (bufferized) into a buffered stream, it becomes a BufferedInputStream in Java.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java BufferedInputStream Class with Examples - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"When an input stream is wrapped (bufferized) into a buffered stream, it becomes a BufferedInputStream in Java.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-02T12:30:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-02T13:09:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/07\/java-buffered-inputstream.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java BufferedInputStream Class with Examples - TechVidvan","description":"When an input stream is wrapped (bufferized) into a buffered stream, it becomes a BufferedInputStream in Java.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/","og_locale":"en_US","og_type":"article","og_title":"Java BufferedInputStream Class with Examples - TechVidvan","og_description":"When an input stream is wrapped (bufferized) into a buffered stream, it becomes a BufferedInputStream in Java.","og_url":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2024-05-02T12:30:15+00:00","article_modified_time":"2024-05-02T13:09:01+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/07\/java-buffered-inputstream.webp","type":"image\/webp"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/dde481bb412350cde1ed6e389bc0deaf"},"headline":"Java BufferedInputStream Class with Examples","datePublished":"2024-05-02T12:30:15+00:00","dateModified":"2024-05-02T13:09:01+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/"},"wordCount":388,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/07\/java-buffered-inputstream.webp","keywords":["bufferedInputStream","bufferedInputStream class","bufferedInputStream class in java","java","java bufferedinputstream","java bufferedinputstream class","Java BufferedInputStream Class with examples","Java Tutorial","java tutorial for beginners","Learn Java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/","url":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/","name":"Java BufferedInputStream Class with Examples - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/07\/java-buffered-inputstream.webp","datePublished":"2024-05-02T12:30:15+00:00","dateModified":"2024-05-02T13:09:01+00:00","description":"When an input stream is wrapped (bufferized) into a buffered stream, it becomes a BufferedInputStream in Java.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/07\/java-buffered-inputstream.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/07\/java-buffered-inputstream.webp","width":1200,"height":628,"caption":"java buffered inputstream"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-bufferedinputstream-class\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Java BufferedInputStream Class with Examples"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/dde481bb412350cde1ed6e389bc0deaf","name":"TechVidvan Team"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/89813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=89813"}],"version-history":[{"count":3,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/89813\/revisions"}],"predecessor-version":[{"id":447483,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/89813\/revisions\/447483"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/447204"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=89813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=89813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=89813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}