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

FileOutPutStream 的写操作

时间:2014-07-18 18:38:10      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:java   os   数据   io   for   re   

package xinhuiji_day07;

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

public class CopyOfTestFileOutPutStream {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        String str = File.separator;
        //String path = File.separator+"home"+File.separator+"han"+File.separator+"FileOutPutStream.txt";
        String path = str+"home"+str+"han"+str+"FileOutPutStream.txt";
        File file = new File(path);
        
//        
//        try {
//            file.createNewFile();
//        } catch (Exception e) {
//            // TODO: handle exception
//        }
        
        OutputStream out = null;
        //out = new FileOutputStream(file);//这种构造方法创建的对象,在每次调用的时候都会覆盖掉原来的数据
        
        out = new FileOutputStream(file, true);//true 表示每次向file中写入数据的时候并不覆盖掉原来的数据
        //而是在之前的文本后面继续添加新的内容
        
        String content = "my name is siashan!";
        byte[] bytes = content.getBytes();
        //out.write(bytes);                        //接受一个byte[]
        for(int i = 0;i<bytes.length;i++){
            
            out.write(bytes[i]);                //接受一个字节
        }
        out.close();

    }

}

FileOutPutStream 的写操作,布布扣,bubuko.com

FileOutPutStream 的写操作

标签:java   os   数据   io   for   re   

原文地址:http://www.cnblogs.com/siashan/p/3853291.html

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