zoukankan      html  css  js  c++  java
  • FileOutPutStream 的写操作

    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();

        }

    }

  • 相关阅读:
    [HNOI2002]营业额统计_Treap
    Catch That Cow_bfs
    Knight Moves
    Hie with the Pie
    tp5.1 错误 No input file specified.
    Jmeter通过BeanShell Sampler获取Jmeter的Bin路径,并存入变量供后面的脚本调用
    Jmeter如何把CSV文件的路径设置成一个变量,且变量的值是一个相对路径
    Autotest Weekly Report
    调试Javascript代码(浏览器F12)
    Javascript中escape()、encodeURI()、encodeURIComponent()的区别
  • 原文地址:https://www.cnblogs.com/siashan/p/3853291.html
Copyright © 2011-2022 走看看