Java InputStreamReader Read readFile(IFile file)

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

Description

read File

License

Apache License

Declaration

public static String readFile(IFile file) throws CoreException 

Method Source Code


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

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

public class Main {
    public static String readFile(IFile file) throws CoreException {
        InputStream inputStream = file.getContents();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        StringBuilder sb = new StringBuilder();
        try {/*from  w w w .  java2s.com*/
            char[] buf = new char[1024];
            int numRead = 0;
            while ((numRead = reader.read(buf)) != -1) {
                sb.append(buf, 0, numRead);
            }
        } catch (IOException e) {
            return null;
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (IOException e) {
                // Nothing
            }
        }
        return sb.toString();
    }
}

Related

  1. readFile(FileInputStream file)
  2. readFile(final File file)
  3. readFile(final File inputFile)
  4. readFile(final String aFileName)
  5. readFile(final String path)
  6. readFile(IFile theFile)
  7. readFile(InputStream aStream)
  8. readFile(InputStream in)
  9. readFile(InputStream in)