Here you can find the source of readFileUtf8(IFile file)
public static String readFileUtf8(IFile file) throws CoreException, IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2013 EclipseSource and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from www. j a va 2 s . c om*/ * Ralf Sternberg - initial implementation and API ******************************************************************************/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; public class Main { public static final String UTF_8 = "UTF-8"; public static String readFileUtf8(IFile file) throws CoreException, IOException { if (file.isAccessible()) { InputStream inputStream = file.getContents(true); try { return readStringUtf8(inputStream); } finally { inputStream.close(); } } return null; } public static String readStringUtf8(InputStream inputStream) throws IOException { BufferedReader reader = createReaderUtf8(inputStream); char[] buffer = new char[1024]; StringBuilder builder = new StringBuilder(); try { int read = reader.read(buffer); while (read != -1) { builder.append(buffer, 0, read); read = reader.read(buffer); } } finally { reader.close(); } return builder.toString(); } public static BufferedReader createReaderUtf8(InputStream inputStream) { try { return new BufferedReader(new InputStreamReader(inputStream, UTF_8)); } catch (UnsupportedEncodingException exception) { throw new RuntimeException(exception); } } }