Java Utililty Methods File Content Read

List of utility methods to do File Content Read

Description

The list of methods to do File Content Read are organized into topic(s).

Method

StringgetFileContents(File testFile)
get File Contents
byte[] buffer = new byte[(int) testFile.length()];
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(testFile))) {
    bis.read(buffer);
    return new String(buffer);
} catch (IOException exception) {
    throw new RuntimeException(exception);
StringgetFileContents(final File f)
get File Contents
return getFileContents(f, DEFAULT_ENCODING);
StringgetFileContents(final File file)
Read the contents of the specified file.
byte[] buffer;
BufferedInputStream inputStream;
inputStream = null;
try {
    inputStream = new BufferedInputStream(new FileInputStream(file));
    buffer = new byte[(int) file.length()];
    inputStream.read(buffer);
} finally {
...
StringgetFileContents(String filename)
reads contents of a (text) file and returns them as a string
BufferedReader br;
if (filename.endsWith(".gz"))
    br = new BufferedReader(
            new InputStreamReader(new GZIPInputStream(new FileInputStream(filename)), "UTF-8"));
else
    br = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "UTF-8"));
StringBuilder sb = new StringBuilder();
while (true) {
...
StringgetFileContents(String fileName)
get File Contents
File file = new File(fileName);
String results = null;
try {
    int length = (int) file.length(), bytesRead;
    byte byteArray[] = new byte[length];
    ByteArrayOutputStream bytesBuffer = new ByteArrayOutputStream(length);
    FileInputStream inputStream = new FileInputStream(file);
    bytesRead = inputStream.read(byteArray);
...