码迷,mamicode.com
首页 > 其他好文 > 详细

I/O

时间:2019-06-26 13:40:57      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:tst   put   otf   file   static   desktop   div   use   throw   

package bbb;

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();
    }
    }
}

 

I/O

标签:tst   put   otf   file   static   desktop   div   use   throw   

原文地址:https://www.cnblogs.com/lcc272165/p/11089168.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!