What is the difference between inputstream and inputstreamreader




















For example we use reader to read form txt file while we use inputstream to read from an excel apache poi API. Then how come both return characters and not binary data? For eg apache poi api gets the exact cell value in character format and not in binary.

So i am really confused. I am also confused as I do not see any difference. The apparent difference seems to be because of the change shown below. In case of FileReader we are casting i to char before printing. Hello Nagraj and Unknown, sorry I see your question now after an year. The difference lies in their purpose - FileReader is meant for reading streams of characters, while For reading streams of raw bytes, consider using a FileInputStream. Also, when you use FileReader default character encoding is used.

Yes, that's correct only difference is that outstream is compared with writer instead of reader because you write on output stream and you read from input stream.

Feel free to comment, ask questions if you have any doubt. You can respecify the encoding in the constructor, otherwise the default encoding of the underlying operating system, such as GBK, will be used.

FileReader and InputStreamReader involve coding transformations either by specifying the encoding or by using the OS default encoding , which can cause confusion on different platforms!

The FileInputStream is processed in binary mode, and there is no garbled code. InputStream provides byte stream reading, not text reading, which is the fundamental difference from the Reader class. Having made the fundamental difference between the two superclasses, let's look at the use of their underlying subclasses. Create a FileInputStream by using the file descriptor fdObj, which represents an existing connection to an actual file in the file system.

Create a FileInputStream by opening a connection to the actual file, which is specified by the pathname name in the file system. BufferedReader: reads the text from the character input stream, buffering the individual characters to enable efficient reading of characters, arrays, and lines.

Creates a buffered character input stream using the default size input buffer. Creates a buffered character input stream that USES the specified size input buffer. The biggest feature of a BufferedReader is the setting of the buffer. Typically, every read request made by the Reader results in a corresponding read request to the underlying character or byte stream, and if there is no buffering, every call to read or readLine results in a byte being read from the file, converted to a character, and returned, which is extremely inefficient.

Use a BufferedReader to specify the size of the buffer or to use the default size. In most cases, the default value is large enough.

Why do we need Generic Types in Java? What does it mean to be static in Java? What are final variables in Java? How Do Annotations Work in Java? How do I use the ternary operator in Java? What is instanceof keyword in Java? How ClassLoader Works in Java? What are fail-safe and fail-fast Iterators in Java What are method references? Does garbage collection guarantee that a program will not run out of memory?

How setting an Object to null help Garbage Collection? How do objects become eligible for garbage collection? How to calculate date difference in Java Difference between Path and Classpath Is Java "pass-by-reference" or "pass-by-value"? Difference between static and nonstatic methods java Why Java does not support pointers? What is package in Java? What are wrapper classes? What is singleton class in Java?



0コメント

  • 1000 / 1000