zoukankan      html  css  js  c++  java
  • FileOutputSteam入门

    FileOutputSteam 字节输入流

    从控制台将字节保存到本地硬盘

    package com.isoftstone.io;
    import java.io.FileOutputStream;
    import java.io.IOException;
    public class TestFileOutStream {
     
     public static void main(String[] args){
      FileOutputStream fos = null;
      try{
       //1、创建文件字节输出流 如果文件不存在,则自动创建
       fos = new FileOutputStream("E:\output.txt"); //这种写法会将原文内容覆盖
       //可以这样写,避免原文被覆盖
       //fos = new FileOutputStream("E:\output.text", true) 
       
       //2、开始写
       String msg = "HelloWorld";
       
       //3、将String转换成byte数组
       byte[] bytes = msg.getBytes();
       
       //4、将bytes数组中的所有数据全部写入
       fos.write(bytes);
       
       //也可以只写入一部分
       //fos.write(bytes, 0,3)
       
       //推荐最后的时候为了保证数据完全写入硬盘,所以要刷新
       fos.flush();
       
       
      }catch(Exception e){
       
      }finally{
       try {
        fos.close();
       } catch (IOException e) {
        e.printStackTrace();
       }
      }
     }
    }
  • 相关阅读:
    JS函数的定义与调用方法
    一次完整的浏览器请求流程
    【前端安全】JavaScript防http劫持与XSS
    深入理解display属性
    前端开发人员需要了解的CSS原理
    第 10 章 文件系统及实现
    第 9 章 虚拟内存管理
    第 8 章 内存管理策略
    第 7 章 死锁
    第 6 章 同步
  • 原文地址:https://www.cnblogs.com/StanLong/p/6926529.html
Copyright © 2011-2022 走看看