Java BufferedReader Read readFile(String file)

Here you can find the source of readFile(String file)

Description

Redid this file to remove sizing requirements and to make it faster Speeded it up 10 fold.

License

Open Source License

Parameter

Parameter Description
file a parameter

Declaration

static String readFile(String file) 

Method Source Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.FileReader;

import java.io.IOException;

public class Main {
    /**//w w  w .j  a  v a 2  s  .c om
     * Redid this file to remove sizing requirements and to make it faster
     * Speeded it up 10 fold.
     *
     * @param file
     */
    static String readFile(String file) {

        try {
            FileReader reader = new FileReader(file);
            BufferedReader read = new BufferedReader(reader);
            StringBuffer b = new StringBuffer();
            String s = null;
            int count = 0;

            while ((s = read.readLine()) != null) {
                count++;

                b.append(s);
                b.append('\n');
            }

            read.close();
            reader.close();

            return b.toString();
        } catch (IOException e) {
            return e.getMessage();
        }
    }
}

Related

  1. readFile(String file)
  2. readFile(String file)
  3. readFile(String file)
  4. readFile(String file)
  5. ReadFile(String file)
  6. readFile(String file)
  7. readFile(String file)
  8. readFile(String file)
  9. readFile(String file)