Here you can find the source of getFileContents(final File file)
Parameter | Description |
---|---|
file | a parameter |
Parameter | Description |
---|
private static String getFileContents(final File file) throws java.io.IOException
//package com.java2s; /*/*from w w w.ja v a 2s . co m*/ * Copyright 2010 jccastrejon * * This file is part of MexADL. * * MexADL 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. * * MexADL 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 MexADL. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; public class Main { /** * Read the contents of the specified file. * * @param file * @return * @throws java.io.IOException */ private static String getFileContents(final File file) throws java.io.IOException { byte[] buffer; BufferedInputStream inputStream; inputStream = null; try { inputStream = new BufferedInputStream(new FileInputStream(file)); buffer = new byte[(int) file.length()]; inputStream.read(buffer); } finally { if (inputStream != null) { inputStream.close(); } } return new String(buffer); } }