Java FileReader Create readTextFileFully(File file)

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

Description

Will skip lines starting with //

License

Open Source License

Declaration

public static String readTextFileFully(File file) 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;

import java.io.Closeable;
import java.io.File;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    /**/*from  www . j a  v  a 2s . c om*/
     * Will skip lines starting with //
     */
    public static String readTextFileFully(File file) {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(file));
            StringBuilder buffer = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                if (!line.startsWith("//")) {
                    buffer.append(line).append('\n');
                }
            }
            return buffer.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            close(reader);
        }
    }

    public static void close(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (Throwable e) {
                // swallow
            }
        }
    }
}

Related

  1. readTextFile(String path)
  2. readTextFile(String text_file_name)
  3. readTextFile(String text_file_name)
  4. readTextFileAsList(File file)
  5. readTextFileContents(File fFile)
  6. readTextFileLines(String fullPathFilename)