Reference:
Http://www.cnblogs.com/plant/p/4637123.html
Https://zhidao.baidu.com/question/32741401.html
Content:
Import Java.io.fileinputstream;import java.io.fileoutputstream;/** * @author Czchina * */public class Teststream {Publ IC static void Main (string[] args) {//TODO auto-generated method Stub//declaration Input Stream Reference FileInputStream FL s = null; Declares a reference to the output stream FileOutputStream fos =null; try{//One, generate the object representing the input stream FLS = new FileInputStream ("E:/android/androidstudioprojects/text.txt"); Generates a byte array of 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)//Note that the length of the data read does not exceed the length of the array. Fls.read (buffer,5,buffer.length-5); Second, generate the object representing the output stream fos = new FileOutputStream ("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 trailing and ending spaces are removed and tested as follows//s = S.trim (); System.out.println (s); } catch (Exception e) {System.out.println (e.tostring ()); } }}
Content added: (String to FileOutputStream)
Import java.io.*;class test{public static void Main (string[] args) throws exception{String str= "Your content"; FileOutputStream fos = new FileOutputStream (new file "filename")); Fos.write (Str.getbytes ());
Java Foundation-output stream-output a string array to a text file