Java File Content Read getFileContent(File file)

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

Description

Returns the content of file as a string.

License

Open Source License

Declaration


public static String getFileContent(File file) throws IOException 

Method Source Code

//package com.java2s;
/*/*from w w w .j  av  a 2 s .c om*/
 * The MIT License (MIT)
 * 
 * Copyright (c) 2010 Technische Universitaet Berlin
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    /**
     * Returns the content of <code>file</code> as a string.
     *
     * @deprecated use repsective method in {@link IOUtil} instead.
     */

    public static String getFileContent(File file) throws IOException {
        FileReader fileReader = new FileReader(file);
        char[] ioBuffer = new char[1024];
        StringBuffer content = new StringBuffer();
        int number = -1;

        while ((number = fileReader.read(ioBuffer)) != -1) {
            content.append(ioBuffer, 0, number);
        }

        return content.toString();
    }

    /**
     * Returns the content of the file named <code>filename</code> as a string.
     *
     * @deprecated use repsective method in {@link IOUtil} instead.
     */

    public static String getFileContent(String filename) throws IOException {
        return getFileContent(new File(filename));
    }
}

Related

  1. getFileContent(File file)
  2. getFileContent(File file)
  3. getFileContent(File file)
  4. getFileContent(File file)
  5. getFileContent(File file)
  6. getFileContent(File file)
  7. getFileContent(File file)
  8. getFileContent(File file)
  9. getFileContent(String filename)