Java InputStreamReader Read readFileWithThrow(IFile in)

Here you can find the source of readFileWithThrow(IFile in)

Description

read File With Throw

License

LGPL

Declaration

public static String readFileWithThrow(IFile in) throws CoreException, IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;

public class Main {
    public static String readFileWithThrow(IFile in) throws CoreException, IOException {
        InputStream contents = in.getContents();
        return readStream(contents);
    }// ww  w.j a  v  a  2 s .  c  o m

    public static String readStream(InputStream is) throws IOException {
        Reader in = new BufferedReader(new InputStreamReader(is));
        StringBuilder result = new StringBuilder(2048);
        char[] buff = new char[2048];
        for (;;) {
            int c = in.read(buff);
            if (c <= 0)
                break;
            result.append(buff, 0, c);
        }
        return result.toString();
    }
}

Related

  1. readFileSB(File f)
  2. readFileToLines(File file)
  3. readFileToList(String fileName, String codeing)
  4. readFileToSet(String filePath, String fileEncoding)
  5. readFileUtf8(IFile file)