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 } }
Java 之文件IO编程 之写入
时间: 2024-10-05 04:45:06