Introduction: Title
ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;/** * @authorCzchina **/ Public classTeststream { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub//declaring a reference to an input streamFileInputStream FLS =NULL; //declaring a reference to the output streamFileOutputStream fos =NULL; Try{ //first, generate an object representing the input streamFLS =NewFileInputStream ("E:/android/androidstudioprojects/text.txt"); //generating a byte array byte[] buffer=New byte[100]; //call the Read method of the input stream object, read the data (put the read length of the <buffer.length-5> data into the buffer array, 5 is the location to start storing)//Note that the length of the data you read does not exceed the length of the array. Fls.read (buffer,5,buffer.length-5); //second, generate an object representing the output streamFOS =NewFileOutputStream ("E:/android/androidstudioprojects/store.txt"); Fos.write (Buffer,0, buffer.length); //string s = new string (buffer); //System.out.println (s); //The trim method of a String object is called, and the string's leading and trailing spaces are removed and tested as follows//s = S.trim (); //System.out.println (s); } Catch(Exception e) {System.out.println (e.tostring ()); } }}
Text.txt
Store.txt
Buffer is like a bucket in the program:
The data flow is based on a Java program:
Java Basics-Input stream-Read text file