java IO复习(二)

package  com.zyw.file;

import java.io.*;

/**
 * Created by zyw on 2016/3/10.
 */
public class FileTest2 {
    public static void main(String args[]){
        File file=new File("G:","work.txt");
        FileOutputStream fos=null;
        DataOutputStream dos=null;
try{
            fos=new FileOutputStream(file);
            dos=new DataOutputStream(fos);
            try {
                dos.writeUTF("沉舟侧畔千帆过,病树前头万木春");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }finally {
            if(dos!=null)
                try {
                    dos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            if(fos!=null)
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }

    }
}

 

posted @ 2016-03-10 22:21  不被女生喜欢好多年  阅读(172)  评论(0编辑  收藏  举报