[Java] java 处理文件名 →→→→→进入此内容的聊天室

来自 , 2021-03-06, 写在 Java, 查看 123 次.
URL http://www.code666.cn/view/9c82c714
  1. /*
  2.  * ProcessFileName.java
  3.  *
  4.  * Created on 2006年8月22日, 下午3:29
  5.  *
  6.  * 文件名的处理
  7.  */
  8. package study.iostudy;
  9.  
  10. import java.io.*;
  11.  
  12. /*
  13.  * 文件名的处理
  14.  * String getName(); 获得文件的名称,不包含文件所在的路径。
  15.  * String getPath(); 获得文件的路径。
  16.  * String getAbsolutePath(); 获得文件的绝对路径。
  17.  * String getParent(); 获得文件的上一级目录的名称。
  18.  * String renameTo(File newName); 按参数中给定的完整路径更改当前的文件名。
  19.  * int compareTo(File pathName); 按照字典顺序比较两个文件对象的路径。
  20.  * boolean isAbsolute(); 测试文件对象的路径是不是绝对路径。
  21.  */
  22. public class ProcesserFileName {
  23.         public static void main(String[] args) {
  24.                 File fileObject1 = new File("d:\\mydir\\firstFile.txt");
  25.                 File fileObject2 = new File("d:\\firstFile.txt");
  26.                 boolean pathAbsolute = fileObject1.isAbsolute();
  27.                 System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * ");
  28.                 System.out
  29.                                 .println("There are some information of fileObject1's file name:");
  30.                 System.out.println("fileObject1: " + fileObject1);
  31.                 System.out.println("fileObject2: " + fileObject2);
  32.                 System.out.println("file name: " + fileObject1.getName());
  33.                 System.out.println("file path: " + fileObject1.getPath());
  34.                 System.out.println("file absolute path: "
  35.                                 + fileObject1.getAbsolutePath());
  36.                 System.out.println("file's parent directory: "
  37.                                 + fileObject1.getParent());
  38.                 System.out.println("file's absoulte path: " + pathAbsolute);
  39.                 int sameName = fileObject1.compareTo(fileObject2);
  40.                 System.out.println("fileObject1 compare to fileObject2: " + sameName);
  41.                 fileObject1.renameTo(fileObject2);
  42.                 System.out.println("file's new name: " + fileObject1.getName());
  43.         }
  44. }

回复 "java 处理文件名"

这儿你可以回复上面这条便签

captcha