Skip to content

Instantly share code, notes, and snippets.

@gtomek
Created February 10, 2016 10:55
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gtomek/72e0c1b4198f76ea90f5 to your computer and use it in GitHub Desktop.
Save gtomek/72e0c1b4198f76ea90f5 to your computer and use it in GitHub Desktop.
Read files with Okio
/**
* Utils for I/O operations.
* <p/>
* Created by Tomek on 09/06/15.
*/
public class IoUtils {
/**
* Reads file and returns a String.
*
* @param file
* @throws IOException
*/
public static String readFile(File file) throws IOException {
BufferedSource source = Okio.buffer(FileSystem.SYSTEM.source(file));
String result = source.readUtf8();
source.close();
return result;
}
/**
* Reads InputStream and returns a String.
*
* @param file
* @throws IOException
*/
public static String readFile(InputStream stream) throws IOException {
BufferedSource source = Okio.buffer(Okio.source(stream));
String result = source.readUtf8();
source.close();
return result;
}
}
@ultraon
Copy link

ultraon commented May 26, 2017

Thank you, i little bit improved this util, see https://gist.github.com/ultraon/c6397dfb23de2f260f81e6946ad5adc2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment