Java BufferedReader Read readFile(String file)

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

Description

read File

License

Apache License

Declaration

public static String readFile(String file) throws IOException, FileNotFoundException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static String readFile(String file) throws IOException, FileNotFoundException {
        if (!(new File(file).exists())) {
            throw new FileNotFoundException("Could not find " + file);
        }//www  .j av  a2s  .  c  o  m
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String content = "";
        String line = "";
        while ((line = reader.readLine()) != null) {
            content += line + "\r\n";
        }
        reader.close();
        int c = content.lastIndexOf("\r\n");
        if (c > 0) {
            content = content.substring(0, c);
        }
        return content;
    }
}

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, Boolean deleteOnExit)