Java File to String fileToString(String fileName)

Here you can find the source of fileToString(String fileName)

Description

file To String

License

Open Source License

Declaration

public static String fileToString(String fileName) throws Exception 

Method Source Code


//package com.java2s;
/* //from  ww w .j a v  a 2 s  .  c  o m
  Copyright (C) 2013 Raquel Pau and Albert Coroleu.
     
 Walkmod is free software: you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
     
 Walkmod 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 Lesser General Public License for more details.
     
 You should have received a copy of the GNU Lesser General Public License
 along with Walkmod.  If not, see <http://www.gnu.org/licenses/>.*/

import java.io.BufferedReader;

import java.io.FileReader;

public class Main {
    public static String fileToString(String fileName) throws Exception {
        StringBuffer result = new StringBuffer();
        BufferedReader in = new BufferedReader(new FileReader(fileName));
        char[] buffer = new char[1000];
        int readedChars = 0;
        try {
            while ((readedChars = in.read(buffer)) > 0) {
                result.append(buffer, 0, readedChars);

            }
        } finally {
            in.close();
        }
        return result.toString();
    }
}

Related

  1. fileToString(String fileName)
  2. fileToString(String fileName)
  3. fileToString(String filename)
  4. fileToString(String filename)
  5. fileToString(String fileName)
  6. fileToString(String filename)
  7. fileToString(String fileName)
  8. fileToString(String fileName)
  9. fileToString(String fileName, String timestamp, String adapterName)