![]() ![]() |
|
创建File文件实例 | |
作者:佚名 文章来源:不详 点击数 更新时间:2008/11/1 20:42:04 文章录入:杜斌 责任编辑:杜斌 | |
|
|
import java.io.*; public class TestFile{ public static void main(String[] args) { String filename = "test.txt"; //文件名 String directory = "testa/testb"; //路径名 File f = new File(directory,filename);//构造File对象 if(f.exists()) { System.out.println("文件名:"+f.getAbsolutePath()); System.out.println("文件大小:"+f.length()); }else{ f.getParentFile().mkdirs();//创建一系列路径 try{ f.createNewFile(); }catch(IOException e){ e.printStackTrace(); } } } } 考试大(www.Examda。com) |
|
![]() ![]() |