コード例 #1
0
 /**
  * Read the contents of a reader and turn it into a string.
  *
  * @param fileReader where to get the string.
  * @return the contents of the file.
  * @throws IOException if an I/O error occurs.
  */
 public static String readerToString(final Reader fileReader) throws IOException {
   final StringBuilder sb = new StringBuilder();
   try (BufferedReader br = new BufferedReader(fileReader)) {
     final char[] buffer = FileUtils.makeBuffer();
     final int eof = -1;
     for (int len = br.read(buffer); len > eof; len = br.read(buffer)) {
       for (int i = 0; i < len; i++) {
         sb.append(buffer[i]);
       }
     }
   }
   return sb.toString();
 }