Java BufferedReader Read readFile(String file)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String file) 

Method Source Code


//package com.java2s;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    public static String readFile(String file) {
        BufferedReader reader;/*w w w  .  j a  v a  2s  . com*/
        StringBuilder stringBuilder = new StringBuilder();
        boolean toggle = false;

        try {
            reader = new BufferedReader(new FileReader(file));
            String line = null;
            String ls = System.getProperty("line.separator");

            while ((line = reader.readLine()) != null) {
                if (toggle) {
                    stringBuilder.append(ls);
                }
                stringBuilder.append(line);
                if (!toggle) {
                    toggle = true;
                }
            }

            reader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return stringBuilder.toString();
    }
}

Related

  1. readFile(String absoluteFilePath)
  2. readFile(String aFileName)
  3. readFile(String directory)
  4. readFile(String directory, String fileName)
  5. readFile(String file)
  6. readFile(String file)
  7. readFile(String file)
  8. readFile(String file)
  9. readFile(String file)