Java BufferedReader Read readFile(String filename)

Here you can find the source of readFile(String filename)

Description

Read an input file.

License

Open Source License

Parameter

Parameter Description
filename the complete path and filename of the file to read.

Exception

Parameter Description
IOException if the file access fails.

Return

the file contents.

Declaration

public static String readFile(String filename) throws IOException 

Method Source Code

//package com.java2s;
/** The FileUtils class contains methods for file and directory handling,
which comprises reading a file, copying or deleting a directory
as well as things like that.//from ww w  .ja v a2  s .  com
    
<pre>
This file is part of FidoCadJ.
    
FidoCadJ is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
FidoCadJ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with FidoCadJ.  If not, see <http://www.gnu.org/licenses/>.
    
Copyright 2008-2015 by Davide Bucci
</pre>
    
*/

import java.io.*;

public class Main {
    /** Read an input file.
    @param filename the complete path and filename of the file to read.
    @return the file contents.
    @throws IOException if the file access fails.
    */
    public static String readFile(String filename) throws IOException {
        FileReader input = new FileReader(filename);
        BufferedReader bufRead = new BufferedReader(input);

        String line = "";
        StringBuffer txt = new StringBuffer(bufRead.readLine());

        txt.append("\n");

        while (line != null) {
            line = bufRead.readLine();
            txt.append(line);
            txt.append("\n");
        }
        bufRead.close();
        return txt.toString();
    }
}

Related

  1. readFile(String filename)
  2. readFile(String filename)
  3. readfile(String filename)
  4. readFile(String fileName)
  5. readFile(String filename)
  6. readFile(String filename)
  7. readFile(String fileName)
  8. readFile(String filename)
  9. readFile(String fileName)