Here you can find the source of readTextFile(String completePath)
Parameter | Description |
---|---|
completePath | complete path of the file |
public static StringBuffer readTextFile(String completePath)
//package com.java2s; /*//from ww w . j a va 2 s.c o m * File: MiscUtil.java * Copyright (c) 2004-2007 Peter Kliem (Peter.Kliem@jaret.de) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ import java.io.File; import java.io.FileReader; public class Main { /** * Read a textfile into a StringBuffer. * * @param completePath complete path of the file * @return StringBuffer */ public static StringBuffer readTextFile(String completePath) { StringBuffer buf = new StringBuffer(); File file = new File(completePath); try { FileReader fr = new FileReader(file); char buffer[] = new char[1024]; int read = 1; while (read > 0) { read = fr.read(buffer); if (read > 0) { buf.append(buffer, 0, read); } } fr.close(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("File could not be read " + completePath + " " + e.getLocalizedMessage()); } return buf; } }