public class Hello {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Hello hello = new Hello();
String path = "D:/abc.txt";
// 写入文件
hello.writeFile(path, "Hello world !");
// 删除文件
//hello.deleteFile(path);
}
/**
* 文件写入
* @param path 文件路径
* @param pValue 写入内容
* @throws IOException IO异常
*/
private void writeFile(String path, String pValue) throws IOException{
File file = new File(path);
FileOutputStream fos = new FileOutputStream(file);
fos.write(pValue.getBytes());
fos.flush();
fos.close();
}
/**
* 根据路径删除文件
* @param path 文件路径
* @throws IOException IO异常
*/
private void deleteFile(String path) throws IOException{
File file = new File(path);
if(file.exists()){
file.delete();
}
}
}
File f=new File("d:/my.txt");
if(!f.exists()){
f.createNewFile();
}
FileWriter out=new FileWriter(f);
out.write("ttttttttt");
out.close();
f.delete();