package com.zyw.file; import java.io.*; /**
* Created by zyw on 2016/3/10.
*/
public class IOTest {
public static void main(String args[]){
File newFile=new File("G:","mywork.txt");//File newFile=new File("G:\\mywork.txt");
if(newFile.exists()){
newFile.delete();
System.out.println(newFile.getName()+"is delete");
}else {
try {
newFile.createNewFile();
System.out.println(newFile.getName()+"is created");
} catch (IOException e) {
e.printStackTrace();
}
}
FileOutputStream os=null;
try {
os=new FileOutputStream(newFile);
try {
os.write("zyw is a smart boy".getBytes());
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally {
//注意一定要将流关闭!!!
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
}