IO流创建文件
public void create1(){
String filePath = "D:\\file1.txt.";File file = new File(filePath);
try {
file.createNewFile();
System.out.println("创建文件1成功");} catch (IOException e) {
e.printStackTrace();
}
提取文件信息
public void Info(){
File file = new File("D:\\file1.txt");
System.out.println("文件名称: "+file.getName());
System.out.println("文件绝对路径: "+ file.getAbsolutePath());
System.out.println("文件父目录: "+file.getParent());
System.out.println("文件大小(字节): "+file.length));
System.out.println("文件是否存在: "+ file.exists());
System.out.println("是否是文件: "+file.isFile());
System.out.println("是否是目录:"+file.isDirectorx());
}
}
public static void main(String[] args) {
String filePath = "D:\\file1.txt.";
File file = new File(filePath);
if (file.exists()) {
if (file.delete()) {
System.out.println(filePath + "删除成功");
} else {
System.out.println(filePath + "删除失败");
}
;
} else {
System.out.println("文件不存在");
}
}
标签:File,filePath,System,javaIO,file,println,out From: https://www.cnblogs.com/wujiale/p/16864402.html