Java File Content Read getFileContents(File f)

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

Description

get File Contents

License

Open Source License

Declaration

public static String getFileContents(File f) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 Red Hat, Inc.//from www.j  av  a2s . c o  m
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

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

public class Main {
    public static String getFileContents(File f) {
        try {
            BufferedReader r = new BufferedReader(new FileReader(f));
            StringBuffer contents = new StringBuffer();
            int c = r.read();
            while (c != -1) {
                contents.append((char) c);
                c = r.read();
            }
            r.close();
            return contents.toString();
        } catch (IOException ioe) {
            return null;
        }
    }
}

Related

  1. getFileContent(String path)
  2. getFileContent(String path)
  3. getFileContent(String path)
  4. getFileContent(String path, String encoding)
  5. getFileContent(String pythonSource)
  6. getFileContents(File f)
  7. getFileContents(File file)
  8. getFileContents(File file)
  9. getFileContents(File methodPatch)