Here you can find the source of readFile(final String fileName)
Parameter | Description |
---|---|
fileName | a parameter |
private static String readFile(final String fileName)
//package com.java2s; /*//from w ww. jav a 2 s. c o m * Fast Code Plugin for Eclipse * * Copyright (C) 2008 Gautam Dev * * This library 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 2.1 of the License, or * (at your option) any later version. * * This library 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 this library; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Plugin Home Page: http://fast-code.sourceforge.net/ */ import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Main { /** * @param fileName * @return */ private static String readFile(final String fileName) { final File file = new File(fileName); char[] buffer = null; try { final BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); buffer = new char[(int) file.length()]; int i = 0; int c = bufferedReader.read(); while (c != -1) { buffer[i++] = (char) c; c = bufferedReader.read(); } } catch (final FileNotFoundException e) { } catch (final IOException e) { } return new String(buffer); } }