在任意文件下创建文件

来源:互联网 发布:网吧充值软件 编辑:程序博客网 时间:2024/05/22 17:12
package com.he.io;
import java.io.*;




public class IO {


public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
//FileWriter fw= new FileWriter("demo.txt");
//fw.write("abcde");
//path表示你所创建文件的路径
String path = "c:/tr/rt";
File f = new File(path);
if(!f.exists()){
f.mkdirs();

// fileName表示你创建的文件名;为txt类型;
String fileName="test.txt";
File file = new File(f,fileName);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}
}
}
}
0 0
原创粉丝点击