zoukankan      html  css  js  c++  java
  • 演示 FileOutputStream案例演示

    /**
     * 演示 FileOutputStream
     * 1:切记一定要先判断文件是否已经存在,否则会把原有的文件覆盖
     */
    package com.test3;
    import java.io.*;
    public class Demo11_3 {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    File f=new File("d:\ss.txt");
    FileOutputStream fos=null;
    if(!f.exists())
    {
    try {
    fos=new FileOutputStream(f);
    String s="老桑,向世界问好 ";
    String s1="美女,向世界问好";
    //定义字节数组
    // byte [] bytes=new byte[1024];
    fos.write(s.getBytes());
    fos.write(s1.getBytes());
    } catch (Exception e) {
    // TODO: handle exception
    }finally
    {
    try {
    fos.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }else
    {
    System.out.println("文件已经存在");
    }
    }

    }

  • 相关阅读:
    iptables
    iftop
    sed&awk
    rz&sz
    关于springboot + mybatis plus 使用事务
    关于JsonArray.toList转换
    jmeter脚本录制
    去掉百度右边的百度热搜等干扰项,集中注意力呀~~
    报错
    图片的异步上传
  • 原文地址:https://www.cnblogs.com/toge/p/6114725.html
Copyright © 2011-2022 走看看