数据i/o

package ccc;

import java.io.*;

public class ccc {
    public static void main(String[] args) throws IOException{
int i=0;
File file=new File("C:\\Users\\Administrator\\Desktop\\文件接收柜\\data.txt"); try { FileWriter fw=new FileWriter(file,true); FileOutputStream out=new FileOutputStream(file); String str = "12345abcdef@#%&*软件工程"; for( i=0;i<str.length()-4;i++){
out.write(str.charAt(i));
} for( ;i<str.length();i++) fw.write(str.charAt(i)); out.close(); fw.close(); }catch(Exception e){ e.printStackTrace(); } try{ FileInputStream in=new FileInputStream(file); byte[] buf=new byte[(int)(file.length())]; in.read(buf); String str=new String(buf); System.out.println(str); in.close(); }catch(FileNotFoundException fn){ System.out.println("文件打开失败!"); }catch(IOException ioe){ ioe.printStackTrace(); } } }

  

上一篇:IO流--SequenceInputStream类(序列流)


下一篇:Java开发笔记(八十八)文件字节I/O流