Use of inputstream in java
Inputstream in java is a byte-oriented stream abstract class. It derives various classes based on specific applications.
For example, FileInputStream is an object that inherits from InputStream and is used to read file streams. Its specific inheritance Structure
We found that it is inherited from the abstract class InputStream.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + ztLDx7zM0Pi/logs/wrzPwsHLoaM8L3A + CjxwPjxwcmUgY2xhc3M9 "brush: java;"> package com. itbuluoge. test; import java. io. fileInputStream; public class ByteInputFile {public static String read () throws Exception {FileInputStream fit = new FileInputStream ("test.txt"); int c; String sb = ""; while (c = fit. read ())! =-1) {sb + = (char) c;} return sb ;} /*** @ param args * @ throws Exception */public static void main (String [] args) throws Exception {// TODO Auto-generated method stubSystem. out. println (read ());}}
Output result
Note that InputStream is a byte-oriented stream. Therefore, each operation is for one byte. Therefore, it cannot process Chinese characters and garbled characters may occur when reading and writing data. The inherited FileInputStream is the same. So here we test that only English characters are used