import java.io.File;
import java.io.IOException;
public class IOLession {
public static void main(String [] args){
//用str存储文件的路径
String str="E:\\工作空间\\java_IO\\src\\com\\hu\\Hello.txt";
//创建file对象
File f=new File(str);
//判断该文件是否存在,如果不存在则在该目录下创建Hello。txt文件
if(!f.exists())
{
try {
//创建文件
f.createNewFile();
System.out.println("创建成功");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
路径思考:
如何动态获取文件的路径?(FileDialog中的对话框的所有者(Frame)不理解导致对话框无法实现)
import java.io.IOException;
public class IOLession {
public static void main(String [] args){
//用str存储文件的路径
String str="E:\\工作空间\\java_IO\\src\\com\\hu\\Hello.txt";
//创建file对象
File f=new File(str);
//判断该文件是否存在,如果不存在则在该目录下创建Hello。txt文件
if(!f.exists())
{
try {
//创建文件
f.createNewFile();
System.out.println("创建成功");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
路径思考:
如何动态获取文件的路径?(FileDialog中的对话框的所有者(Frame)不理解导致对话框无法实现)