Here you can find the source of getFileContent(final File file)
Parameter | Description |
---|---|
file | file. |
Parameter | Description |
---|---|
IOException | error while reading. |
InterruptedException | task cancelled. |
public static String getFileContent(final File file) throws IOException, InterruptedException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { /**/* w w w .j a va 2 s. c om*/ * Get the content of a file. * * @param file * file. * @return its content. * @throws IOException * error while reading. * @throws InterruptedException * task cancelled. */ public static String getFileContent(final File file) throws IOException, InterruptedException { try (BufferedReader br = new BufferedReader(new FileReader(file))) { String line = null; final StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { // Check for interrupt. if (Thread.currentThread().isInterrupted()) { throw new InterruptedException(); } // Read next line. sb.append(line); } return sb.toString(); } } }