Here you can find the source of hasLeadingWhitespace(File inputFile)
Parameter | Description |
---|---|
inputFile | the file to check for leading whitespace |
Parameter | Description |
---|---|
IOException | if the file cannot be read |
public static boolean hasLeadingWhitespace(File inputFile) throws IOException
//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; } }