Apache Commons IO - IOCase Enum



Overview

IOCase is an Enumeration of IO case sensitivity. Different Operating systems have different rules for case-sensitivity for file names. For example, Windows is case-insensitive for file naming while Unix is case-sensitive. IOCase captures that difference, provides an enumeration to control how filename comparisons should be performed. It also provides methods to use the enumeration to perform comparisons.

Enum Declaration

Following is the declaration for org.apache.commons.io.IOCase Enum −

public enum IOCase
   extends Enum<IOCase> implements Serializable

Example - Case Sensitive Check on a String

CommonsIoTester.java

package com.tutorialspoint;

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

public class CommonsIoTester {
   public static void main(String[] args) throws IOException {
      String text = "WELCOME TO TUTORIALSPOINT. SIMPLY EASY LEARNING.";
      System.out.println("Ends with Learning (case sensitive): " + IOCase.SENSITIVE.checkEndsWith(text, "Learning."));
   }
}

Output

It will print the following result −

Ends with Learning (case sensitive): false

Example - Case Insensitive Check on a String

CommonsIoTester.java

package com.tutorialspoint;

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

public class CommonsIoTester {
   public static void main(String[] args) throws IOException {
      String text = "WELCOME TO TUTORIALSPOINT. SIMPLY EASY LEARNING.";
      System.out.println("Ends with Learning (case insensitive): " + IOCase.INSENSITIVE.checkEndsWith(text, "Learning."));
   }
}

Output

It will print the following result −

Ends with Learning (case insensitive): true

Example - Case Sensitive Equality Check on Strings

CommonsIoTester.java

package com.tutorialspoint;

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

public class CommonsIoTester {
   public static void main(String[] args) throws IOException {
      String text = "Welcome to TutorialsPoint. Simply Easy Learning.";
      String text1 = "WELCOME TO TUTORIALSPOINT. SIMPLY EASY 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));
   }
}

Output

It will print the following result −

Equality Check (case sensitive): false
Equality Check (case insensitive): true
Advertisements