您的位置:首页 > 编程语言 > Java开发

Java IO复习(一)

2016-03-10 18:44 309 查看
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();
}
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: