Here you can find the source of readFile(String absoluteFilePath)
Parameter | Description |
---|---|
absoluteFilePath | : The absolute path of the file from which to read. |
public static String readFile(String absoluteFilePath)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009 Red Hat, Inc./*from ww w .ja v a2 s .co m*/ * All rights reserved. This program and the accompanying materials * are 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 - initial API and implementation *******************************************************************************/ import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Main { /** * Read the contents of a file * @param absoluteFilePath : The absolute path of the file from which to read. * @return : The contents of the file as a String. */ public static String readFile(String absoluteFilePath) { try (BufferedReader bw = new BufferedReader(new FileReader( new File(absoluteFilePath)))) { String output = ""; //$NON-NLS-1$ String tmp = ""; //$NON-NLS-1$ while ((tmp = bw.readLine()) != null) { output += tmp + "\n"; //$NON-NLS-1$ } bw.close(); return output; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } }