{"id":89852,"date":"2025-09-09T18:00:27","date_gmt":"2025-09-09T12:30:27","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=89852"},"modified":"2025-09-09T18:05:47","modified_gmt":"2025-09-09T12:35:47","slug":"inputstreamreader-class-in-java","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/","title":{"rendered":"InputStreamReader Class in Java"},"content":{"rendered":"<p>In Java, an InputStreamReader is a character input stream that gets its data from a stream of bytes.<\/p>\n<p>It transforms a byte stream into a character stream by acting as a bridge between an incoming stream of bytes and an outgoing sequence of characters.<\/p>\n<h2>Explanation<\/h2>\n<p>A bridge connecting byte streams and character streams is an input stream reader: It uses a given charset to decode the bytes it reads into characters. It can be specified explicitly or by name, or it can accept the default charset used by the platform.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public class InputStreamReader  extends Reader<\/pre>\n<h4>Example<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public class InputStreamReader\r\n {  \r\n    public static void main(String[] args) \r\n{  \r\n        Try\r\n  {  \r\n            InputStream stream = new FileInputStream(\"file.txt\");  \r\n            Reader reader = new InputStreamReader(stream);  \r\n            int data = reader.read();  \r\n            while (data != -1) {  \r\n                System.out.print((char) data);  \r\n                data = reader.read();  \r\n            }  \r\n        } \r\ncatch (Exception e)\r\n {  \r\n            e.printStackTrace();  \r\n        }  \r\n    }  \r\n}<\/pre>\n<p><strong>Output<\/strong><br \/>\nJava Programming<\/p>\n<h3>Constructor<\/h3>\n<ul>\n<li><strong>InputStreamReader(InputStream in):<\/strong><\/li>\n<\/ul>\n<p>Using the built-in character encoding, this constructor turns bytes into characters by creating an InputStreamReader object.<\/p>\n<ul>\n<li><strong>InputStreamReader(InputStream in, String charsetName):<\/strong><\/li>\n<\/ul>\n<p>Using the specified character encoding, an InputStreamReader object is created by this constructor.<\/p>\n<ul>\n<li><strong>InputStreamReader(InputStream in, Charset cs):<\/strong><\/li>\n<\/ul>\n<p>Using the given charset, this character creates an inputStreamReader object that decodes bytes into characters.<\/p>\n<ul>\n<li><strong>InputStreamReader(InputStream in, CharsetDecoder dec):<\/strong><\/li>\n<\/ul>\n<p>This constructor uses the given charset decoder to create an instance of an InputStreamReader object.<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Constructor<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">InputStreamReader(InputStream in)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">By default, the default charset is used when creating an InputStreamReader.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">InputStreamReader(InputStream in, Charset cs)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Using the specified charset, it generates an InputStreamReader.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">InputStreamReader(InputStream in, CharsetDecoder dec)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Using the supplied charset decoder, it generates an InputStreamReader.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">InputStreamReader(InputStream in, String charsetName)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">It uses the named charset to create an InputStreamReader.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Methods<\/h3>\n<h4>String getEncoding()<\/h4>\n<p>The character encoding name used by this stream is returned by this method.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public String getEncoding()<\/pre>\n<h4>Int read()<\/h4>\n<p>One character is read using this method.<br \/>\n<strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Public int read()<\/pre>\n<h4>int read(char[ ] charBuffer, int offset, int length)<\/h4>\n<p>Using this technique, characters are read into a section of an array.<\/p>\n<h4>close()<\/h4>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Public void close()<\/pre>\n<h4>boolean ready()<\/h4>\n<p>This procedure determines if the stream is prepared for reading. If the stream is ready for reading, it returns true.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Public boolean ready()<\/pre>\n<table>\n<tbody>\n<tr>\n<td><strong>Method<\/strong><\/td>\n<td><strong>Type<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">close()<\/span><\/td>\n<td><span style=\"font-weight: 400;\">void<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Shuts off the stream and frees up any related system resources.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">getEncoding()<\/span><\/td>\n<td><span style=\"font-weight: 400;\">String<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Returns the name of the character encoding used by this stream.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">read()<\/span><\/td>\n<td><span style=\"font-weight: 400;\">int<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Reads just a single word.<\/span><\/td>\n<\/tr>\n<tr>\n<td>read(char[] cbuf, int offset, int length)<\/td>\n<td><span style=\"font-weight: 400;\">int<\/span><\/td>\n<td><span style=\"font-weight: 400;\">A section of an array is read with characters.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ready()<\/span><\/td>\n<td><span style=\"font-weight: 400;\">boolean<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Indicates if it is appropriate to read this stream.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Example<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import java.io.*;\r\n\r\npublic class NewClass\r\n{\r\n\r\n    public static void main(String[] args)\r\n\r\n    {\r\n        try\r\n\r\n        {\r\n            FileInputStream g = new FileInputStream(\"ABC.txt\");\r\n \r\n            InputStreamReader in_strm = new InputStreamReader(g);\r\n\r\n            int t;\r\n\r\n            while((t=in_strm.read())!= -1)\r\n\r\n            {\r\n                char r = (char)t;\r\n                System.out.println(\"Character : \"+r);\r\n                boolean b = in_strm.ready();\r\n                System.out.println(\"Ready? : \"+b);\r\n \r\n\r\n            }\r\n\r\n            in_strm.close();\r\n            g.close();\r\n\r\n        }\r\n\r\n        catch (FileNotFoundException fnfe)\r\n\r\n        {\r\n\r\n            System.out.println(\"NO Such File Exists\");\r\n\r\n        }\r\n\r\n        catch (IOException except)\r\n\r\n        {\r\n            System.out.println(\"IOException occurred\");\r\n        }\r\n\r\n    }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><strong>Character:<\/strong> J<br \/>\n<strong>Ready?<\/strong>: true<br \/>\n<strong>Character:<\/strong> a<br \/>\n<strong>Ready?:<\/strong> true<br \/>\n<strong>Character:<\/strong> v<br \/>\n<strong>Ready?:<\/strong> true<br \/>\n<strong>Character:<\/strong> a<br \/>\n<strong>Ready?:<\/strong> true<br \/>\n<strong>Character:<\/strong> P<br \/>\n<strong>Ready?:<\/strong> true<br \/>\n<strong>Character:<\/strong> r<br \/>\n<strong>Ready?:<\/strong> true<br \/>\n<strong>Character:<\/strong> o<br \/>\n<strong>Ready?:<\/strong> true<br \/>\n<strong>Character:<\/strong> g<br \/>\n<strong>Ready?:<\/strong> true<br \/>\n<strong>Character:<\/strong> r<br \/>\n<strong>Ready?:<\/strong> true<br \/>\n<strong>Character:<\/strong> a<br \/>\n<strong>Ready?:<\/strong> true<br \/>\n<strong>Character:<\/strong> m<br \/>\n<strong>Ready?:<\/strong> true<\/p>\n<h4>Example<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package javaProgram;\r\nimport java.io.FileInputStream;\r\nimport java.io.InputStreamReader;\r\npublic class InputStreamReaderExample {\r\npublic static void main(String[] args)\r\n{\r\ntry {  \r\n   FileInputStream frs = new FileInputStream(\"D:\\\\myfile.txt\");\t\r\n  \r\n   InputStreamReader inStream = new InputStreamReader(frs);  \r\n\r\n int data = inStream.read(); \r\n while (data != -1) {  \r\n   System.out.print((char) data);  \r\n    data = inStream.read();  \r\n } \r\n inStream.close();  \r\n} catch (Exception ex) {  \r\n   System.out.println(ex.getMessage());  \r\n }  \r\n }\r\n}<\/pre>\n<p><strong>Output<\/strong><br \/>\nJAVA<\/p>\n<h3>Conclusion<\/h3>\n<p>One benefit of Java is the InputStreamReader, which facilitates reading and modifying file content. It utilises every method in the InputStream subclass, which it inherited from the parent reader class. For this reason, every process in the subclass helps make any changes, as well as for reading, writing, and creating the InputStreamReader buffer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Java, an InputStreamReader is a character input stream that gets its data from a stream of bytes. It transforms a byte stream into a character stream by acting as a bridge between an&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":447381,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[346,347,348,296,349,350,299,263,250],"class_list":["post-89852","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-inputstreamreader","tag-inputstreamreader-class-in-java","tag-inputstreamreader-in-java","tag-java","tag-java-inputstreamreader","tag-java-inputstreamreader-class","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>InputStreamReader Class in Java - TechVidvan<\/title>\n<meta name=\"description\" content=\"The Java InputStreamReader utilises every method in the InputStream subclass, which it inherits from the parent Reader class.\" \/>\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\/inputstreamreader-class-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"InputStreamReader Class in Java - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"The Java InputStreamReader utilises every method in the InputStream subclass, which it inherits from the parent Reader class.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/\" \/>\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=\"2025-09-09T12:30:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-09T12:35:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/09\/java-inputstreamreader.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=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"InputStreamReader Class in Java - TechVidvan","description":"The Java InputStreamReader utilises every method in the InputStream subclass, which it inherits from the parent Reader class.","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\/inputstreamreader-class-in-java\/","og_locale":"en_US","og_type":"article","og_title":"InputStreamReader Class in Java - TechVidvan","og_description":"The Java InputStreamReader utilises every method in the InputStream subclass, which it inherits from the parent Reader class.","og_url":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2025-09-09T12:30:27+00:00","article_modified_time":"2025-09-09T12:35:47+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/09\/java-inputstreamreader.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":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/dde481bb412350cde1ed6e389bc0deaf"},"headline":"InputStreamReader Class in Java","datePublished":"2025-09-09T12:30:27+00:00","dateModified":"2025-09-09T12:35:47+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/"},"wordCount":473,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/09\/java-inputstreamreader.webp","keywords":["inputstreamreader","inputstreamreader class in java","inputstreamreader in java","java","java inputstreamreader","java inputstreamreader class","Java Tutorial","java tutorial for beginners","Learn Java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/","url":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/","name":"InputStreamReader Class in Java - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/09\/java-inputstreamreader.webp","datePublished":"2025-09-09T12:30:27+00:00","dateModified":"2025-09-09T12:35:47+00:00","description":"The Java InputStreamReader utilises every method in the InputStream subclass, which it inherits from the parent Reader class.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/09\/java-inputstreamreader.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/09\/java-inputstreamreader.webp","width":1200,"height":628,"caption":"java inputstreamreader"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/inputstreamreader-class-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"InputStreamReader Class in Java"}]},{"@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\/89852","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=89852"}],"version-history":[{"count":3,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/89852\/revisions"}],"predecessor-version":[{"id":447848,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/89852\/revisions\/447848"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/447381"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=89852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=89852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=89852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}