BYTE input stream:
1.FileInputStream
Purpose: Obtain input bytes from files in file system, often used to read raw byte stream of image, sound, etc., read character flow, consider using FileReader
Detailed constructors and common methods can refer to the API documentation, online already has the Chinese version of the API, I am an e illiterate, hurt
Here's one of the most common ways to do this:
read(byte[] b, int off, int len)
len
reads the most bytes of data from this input stream into a byte array.
->off:b the offset in the byte array
Tip: Array offset, such as a[1,2,3,4,5] array, the default array first should point to a[0], if the offset is 2, point to a[1]
Case:
Import Java.io.fileinputstream;import Java.io.filenotfoundexception;import Java.io.ioexception;public class Test {/* * * @param args */public static void main (string[] args) {//TODO auto-generated method stubtry {int b;//create an input stream FILEINPUTST Ream ReadFile = new FileInputStream ("E:\\test.txt"); byte buffer[] = new byte[2500];//creates a byte array//reads bytes from the input stream and stores it in the buffer array. The longest reads 2,500 bytes, the return value B is the actual read length B = readfile.read (buffer, 1, 2000);//1 is the starting offset in the buffer array, string str = new string (buffer, 0, B, "Defa Ult "); System.out.println (str); System.out.println (b); Readfile.close ();} catch (FileNotFoundException e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//Todo Au To-generated catch Blocke.printstacktrace ();}}}
Not to be continued, there are a lot of commonly used flow operations, will be added later, very late, the bed, every day to take a little time to learn, slowly accumulate, I can do it!!