zoukankan      html  css  js  c++  java
  • Java 之文件IO编程 之写入

    package com.sun;
    /*
     * 操作对文件IO的写
     * 2014-08-10
     */
    import java.io.*;
    public class File_Write {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            FileOutputStream fos=null;
            //创建一个文件对象
             File file_writer  = new File ("d:\bb.txt");
           //加入到一个输出流
             try {
                 fos = new  FileOutputStream(file_writer);
                String s = "上山打老虎";
                 byte[] bytes = new byte[1024];
                fos.write(s.getBytes());
                fos.write(s.getBytes());
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally{
                try {
                    fos.close();//关闭此文件输出流并释放与此流有关的所有系统资源。
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }        
        }
        public File_Write() {
            // TODO Auto-generated constructor stub
        }
    
    }
  • 相关阅读:
    实验四
    密码破解技术
    222
    111
    6
    5
    4
    第三次
    第二次
    第一次
  • 原文地址:https://www.cnblogs.com/sunxun/p/3902447.html
Copyright © 2011-2022 走看看