litesoft
@ 961
litesoft / trunk / DeviceDesktopTest / src / org / litesoft / utils / FileUtils.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
package org.litesoft.utils; import java.io.*; public class FileUtils { public static final String UTF_8 = "UTF-8"; public static String loadTextFileAsString( InputStream pInputStream, String pLineSeparator ) throws IOException { StringBuilder buffer = new StringBuilder(); BufferedReader reader = createReader( pInputStream ); boolean closed = false; try { int count = 0; for ( String line; null != (line = reader.readLine()); count++ ) { if ( count > 0 ) { buffer.append( pLineSeparator ); } buffer.append( line ); } closed = true; reader.close(); } finally { if ( !closed ) { try { reader.close(); } catch ( IOException ignore ) { // Whatever... } } } return buffer.toString(); } public static BufferedReader createReader( InputStream pInputStream ) throws IOException { return new BufferedReader( new InputStreamReader( pInputStream, UTF_8 ) ); } } |