java 创建一个File文件对象


 

 

Example10_1.java

import java.io.*;
public class Example10_1 {
   public static void main(String args[]) {
      File f = new File("C:\\ch10","Example10_1.java");
      System.out.println(f.getName()+"是可读的吗:"+f.canRead());
      System.out.println(f.getName()+"的长度:"+f.length());
      System.out.println(f.getName()+"的绝对路径:"+f.getAbsolutePath());
      File file = new File("new.txt");
      System.out.println("在当前目录下创建新文件"+file.getName());
      if(!file.exists()) {
         try {
              file.createNewFile();
              System.out.println("创建成功");
         }
         catch(IOException exp){}
      }
   }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM