Java Is Text File isTextFile(File file)

Here you can find the source of isTextFile(File file)

Description

Checks whether the file is a test file.

License

LGPL

Parameter

Parameter Description
file the file to check

Return

true if the file is text file.

Declaration

public static boolean isTextFile(File file) 

Method Source Code

//package com.java2s;
/*//from  w w  w  .  j a va 2s .c  o  m
 *   This software is distributed under the terms of the FSF
 *   Gnu Lesser General Public License (see lgpl.txt).
 *
 *   This program is distributed WITHOUT ANY WARRANTY. See the
 *   GNU General Public License for more details.
 */

import java.io.File;

import java.util.HashSet;

import java.util.Set;

public class Main {
    private static final Set<String> asciiFileExtensions = new HashSet<String>();

    /**
     * Checks whether the file is a test file. This method should only be used 
     * by Scooter's code generator.
     * 
     * @param file  the file to check
     * @return true if the file is text file.
     */
    public static boolean isTextFile(File file) {
        boolean check = false;
        String fileName = file.getName();
        int lastDot = fileName.lastIndexOf('.');
        if (lastDot != -1) {
            String extension = fileName.substring(lastDot + 1);
            check = asciiFileExtensions.contains(extension);
        }
        return check;
    }
}

Related

  1. isText(File file)
  2. isText(File file)
  3. isTextFile(File f)
  4. isTextFile(File f, int length)
  5. isTextFile(File file)