创建File文件实例 |
|
www.nanhushi.com 佚名 不详 |
一个最基本创建File文件的例子,考试大提示记录如下: 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)
|
|
|
文章录入:杜斌 责任编辑:杜斌 |
|
上一篇文章: JAVA基础Comparable 下一篇文章: JAVA基础(JAVA移位运算符) |
【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |
|
|