Here you can find the source of readfile(String filename)
Parameter | Description |
---|---|
filename | file to read, '-'|null => stdin. |
Parameter | Description |
---|---|
IOException | an exception |
static public String readfile(String filename) throws IOException
//package com.java2s; /*/*from www . j av a 2 s .c o m*/ This software is released under the Licence terms described in the file LICENSE.txt. */ import java.io.*; public class Main { /** * Read the contents of a file. * * @param filename file to read, '-'|null => stdin. * @return The contents of the file as a string * @throws IOException */ static public String readfile(String filename) throws IOException { InputStream input = null; if (filename == null) input = System.in; else input = new FileInputStream(filename); InputStreamReader rdr = new InputStreamReader(input, "UTF-8"); int c = 0; StringBuilder buf = new StringBuilder(); while ((c = rdr.read()) >= 0) { buf.append((char) c); } input.close(); return buf.toString(); } }