Java BufferedReader Read loadContents(File file)

Here you can find the source of loadContents(File file)

Description

load Contents

License

Apache License

Declaration

public static String loadContents(File file) throws IOException 

Method Source Code


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

import java.io.*;

public class Main {
    public static String loadContents(File file) throws IOException {
        if (file == null) {
            throw new IllegalArgumentException();
        }//  w ww.j  a v a 2  s.c  o  m
        if (!file.exists() || file.isDirectory()) {
            return null;
        }
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
            String s = null;
            StringBuilder sb = new StringBuilder();
            while ((s = br.readLine()) != null) {
                sb.append(s);
                sb.append("\r\n");
            }
            return sb.toString();
        } finally {
            if (br != null) {
                br.close();
            }
        }
    }
}

Related

  1. loadClob(File f, String enc)
  2. loadCommonMisspellingsFile(String commonMisspellingsFileLocation)
  3. loadConfFile(String filename, String key)
  4. loadConfig(File conf)
  5. loadConfigProps(String configFile)
  6. loadCredentials(File credentials)
  7. loadCsvFile(String fileWithPath, String delimiter)
  8. loadDataURLs(File f, Pattern p)
  9. loadDict(InputStream io, boolean case_sensitive)