码迷,mamicode.com
首页 > 其他好文 > 详细

IO流OutputStream

时间:2018-07-27 01:11:25      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:code   todo   generated   java   txt   ati   ack   rac   print   

package outputStream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class Demo {
    
        public static void main(String[] args) {
            writerFile();
            // System.out.println("done");
        }
        public static void writerFile() {
            OutputStream out  =null;
            
            try {
                /**
        追加    out = new FileOutputStream("e.txt",true);
                 * 
                 */
            out = new FileOutputStream("e.txt");
            String str = "helloworldaaaaaaaaa";
            byte [] bs = str.getBytes();
//            out.write(bs);
//        out.write(bs);       和下面一样
            for(byte b:bs) {
                out.write(b);
                
                
                //System.out.print((char)b);
            }
            out.flush();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally {
                if(out!=null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }
}

 

IO流OutputStream

标签:code   todo   generated   java   txt   ati   ack   rac   print   

原文地址:https://www.cnblogs.com/java-jiangtao-home/p/9374969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!