New IOUtil class

This commit is contained in:
Ziver Koc 2010-10-27 18:04:52 +00:00
parent ca8f6278b1
commit 64e00e174d
3 changed files with 196 additions and 25 deletions

36
src/zutil/io/IOUtil.java Normal file
View file

@ -0,0 +1,36 @@
package zutil.io;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* Utility class for streams and general IO stuff
*
* @author Ziver
*
*/
public class IOUtil {
/**
* Reads and returns the content of a file as a String.
* Or use FileUtils.readFileToString(file);
*
* @param stream is the file stream to read
* @return The file content
* @throws IOException
*/
public static String getContent(InputStream stream) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(stream));
StringBuffer ret = new StringBuffer();
int tmp;
while((tmp=in.read()) != -1){
ret.append((char)tmp);
}
in.close();
return ret.toString();
}
}