📜  Apache Commons IO-IOCase

📅  最后修改于: 2020-11-18 08:15:50             🧑  作者: Mango


IO区分大小写的枚举。不同的操作系统对于文件名区分大小写有不同的规则。例如,Windows对于文件命名不区分大小写,而Unix对大小写敏感。 IOCase捕获了这种差异,提供了枚举来控制应如何执行文件名比较。它还提供了使用枚举执行比较的方法。

枚举声明

以下是org.apache.commons.io.IOCase枚举的声明-

public enum IOCase
   extends Enum implements Serializable

IOCase枚举示例

IOTester.java

import java.io.IOException;
import org.apache.commons.io.IOCase;

public class IOTester {
   public static void main(String[] args) {
      try {
         usingIOCase();
      } catch(IOException e) {
         System.out.println(e.getMessage());
      }
   }

   public static void usingIOCase() throws IOException {
      String text = "Welcome to TutorialsPoint. Simply Easy Learning.";
      String text1 = "WELCOME TO TUTORIALSPOINT. SIMPLY EASY LEARNING.";

      System.out.println("Ends with Learning (case sensitive): " +
      IOCase.SENSITIVE.checkEndsWith(text1, "Learning."));

      System.out.println("Ends with Learning (case insensitive): " +
      IOCase.INSENSITIVE.checkEndsWith(text1, "Learning."));

      System.out.println("Equality Check  (case sensitive): " +
      IOCase.SENSITIVE.checkEquals(text, text1));

      System.out.println("Equality Check  (case insensitive): " +
      IOCase.INSENSITIVE.checkEquals(text, text1));
   }
}

输出

它将打印以下结果。

Ends with Learning (case sensitive): false
Ends with Learning (case insensitive): true
Equality Check  (case sensitive): false
Equality Check  (case insensitive): true