Java Is Text File isTextFile(File f)

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

Description

is Text File

License

Open Source License

Declaration

private static boolean isTextFile(File f) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    private static boolean isTextFile(File f) {
        if (!f.isFile()) {
            return false;
        }/*from ww  w .j a va 2  s . c  om*/

        final String name = f.getName();
        final int lastDotIdx = name.lastIndexOf('.');
        if (lastDotIdx < 0) {
            return false;
        }

        final String extension = name.substring(lastDotIdx + 1);
        switch (extension) {
        case "buildinfo":
        case "html":
        case "css":
        case "js":
        case "svg":
        case "txt":
        case "xml":
            return true;
        case "map":
            return name.endsWith(".css.map") || name.endsWith(".js.map");
        }

        return false;
    }
}

Related

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