Here you can find the source of readFile(String filename)
public static String readFile(String filename)
//package com.java2s; /*// w w w . ja v a 2 s . c o m * -------------------------------------------------------- * Module Name : binding-upnp * Version : 0.1-SNAPSHOT * * Software Name : HomeNap * Version : 0.1-SNAPSHOT * * Copyright ? 28/06/2012 ? 31/12/2013 France T?l?com * This software is distributed under the Apache 2.0 license, * the text of which is available at http://www.apache.org/licenses/LICENSE-2.0.html * or see the "LICENSE-2.0.txt" file for more details. * * -------------------------------------------------------- * File Name : ${NAME} * * Created : * Author(s) : Remi Druilhe * * Description : * * -------------------------------------------------------- */ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; public class Main { public static String readFile(String filename) { File f = new File(filename); InputStream stream = null; try { stream = new FileInputStream(f); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } int ch = 0; StringBuffer buffer = new StringBuffer(); int len; try { len = stream.available(); if (len != -1) { for (int i = 0; i < len; i++) if ((ch = stream.read()) != -1) buffer.append((char) ch); } } catch (IOException e) { e.printStackTrace(); } String xmlFile = buffer.toString(); return xmlFile; } }