Apache Commons IO - IOCase



列舉 IO 大小寫敏感性。不同的作業系統對檔名的區分大小寫規則不同。例如,Windows 對檔案命名不區分大小寫,而 Unix 則區分大小寫。IOCase 捕獲了這種差異,提供列舉來控制如何執行檔名比較。它還提供使用列舉執行比較的方法。

列舉宣告

以下是 org.apache.commons.io.IOCase 列舉的宣告 -

public enum IOCase
   extends Enum<IOCase> implements Serializable

IOCase 列舉示例

下面提供了 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
廣告