Java Foundation-output stream-output a string array to a text file

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.