Java UTF8 hasLeadingWhitespace(File inputFile)

Here you can find the source of hasLeadingWhitespace(File inputFile)

Description

Checks whether a file contains any leading whitespace characters.

License

Open Source License

Parameter

Parameter Description
inputFile the file to check for leading whitespace

Exception

Parameter Description
IOException if the file cannot be read

Return

true if file starts with whitespace

Declaration

public static boolean hasLeadingWhitespace(File inputFile) throws IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;

import java.nio.file.Files;

public class Main {
    /**//from   ww w.j  ava  2  s.  co m
     * Checks whether a file contains any leading whitespace characters.
     *
     * @param inputFile the file to check for leading whitespace
     * @return true if file starts with whitespace
     * @throws IOException if the file cannot be read
     */
    public static boolean hasLeadingWhitespace(File inputFile) throws IOException {
        BufferedReader reader = Files.newBufferedReader(inputFile.toPath());
        int character = reader.read();
        if (character != -1 && Character.isWhitespace((char) character)) {
            return true;
        }
        reader.close();
        return false;
    }
}

Related

  1. getUtf8OrDefault()
  2. getUTF8Reader(InputStream f)
  3. getUtf8String(URL url)
  4. getUTF8SuportOutput()
  5. getUTF8Writer(String path)
  6. inputStreamToFile(final InputStream inputStream, final File outputFile)
  7. isSystemUtf8()
  8. isUtf8Supported()
  9. loadStringUTF8(InputStream in)