Java Utililty Methods FileReader Read

List of utility methods to do FileReader Read

Description

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

Method

StringreadFile(String filename)
Returns the content of the file with the specified name as a string.
return readFile(new File(filename));
StringreadFile(String fileName)
read File
StringBuffer result = new StringBuffer();
char b[] = new char[2048];
FileReader fis = new FileReader(fileName);
int n;
while ((n = fis.read(b)) > 0) {
    result.append(b, 0, n);
fis.close();
...
StringreadFile(String filename)
Read a file's contents into a string.
File file = new File(filename);
StringBuffer buf = new StringBuffer((int) file.length() + 2);
FileReader in = new FileReader(file);
int c;
while ((c = in.read()) != -1) {
    buf.append((char) c);
in.close();
...
StringreadFile(String filename)
read File
String res = "";
FileReader in = new FileReader(filename);
char[] buffer = new char[1024];
int n = 1;
while (n > 0) {
    n = in.read(buffer, 0, buffer.length);
    if (n > 0) {
        res += new String(buffer, 0, n);
...
StringreadFile(String fileName)
read File
StringBuffer sb = new StringBuffer();
Vector v = readFileByLine(fileName);
boolean isDataInVector = (v.size() > 0);
if (isDataInVector) {
    for (int i = 0; i < v.size(); i++) {
        sb.append(v.elementAt(i));
        sb.append("\n");
    return sb.toString();
} else {
    return null;
voidreadFile(String fileName, StringBuffer buffer)
Reads a file into a StringBuffer.
FileReader fr = new FileReader(fileName);
buffer.setLength(0);
int c;
while ((c = fr.read()) != -1) {
    buffer.append((char) c);
fr.close();
String[]readFileAsArray(String filename)
Reads a file into a string array
LinkedList<String> file = new LinkedList<String>();
String[] lines = new String[0];
String line;
FileReader reader = null;
LineNumberReader lineReader = null;
try {
    reader = new FileReader(filename);
    lineReader = new LineNumberReader(reader);
...
StringreadFileOrThrow(File file)
Reads the contents of a File.
Reader reader = null;
try {
    reader = new FileReader(file);
    char[] buf = new char[8192];
    int len;
    StringBuilder s = new StringBuilder();
    while ((len = reader.read(buf)) >= 0) {
        s.append(buf, 0, len);
...