java IO复习(二)

时间:2023-03-24 19:45:32
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();
}
} }
}