Skip to content

Instantly share code, notes, and snippets.

@maoruibin
Last active January 13, 2016 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maoruibin/f41251d3845daddca131 to your computer and use it in GitHub Desktop.
Save maoruibin/f41251d3845daddca131 to your computer and use it in GitHub Desktop.
method of copy file
/**
* copy file
* @param source
* @param dest
* @throws IOException
*/
public static void copyFileUsingFileChannels(File source, File dest)
throws IOException {
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
inputChannel = new FileInputStream(source).getChannel();
outputChannel = new FileOutputStream(dest).getChannel();
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} finally {
inputChannel.close();
outputChannel.close();
}
}
// convert InputStream to String
// NB: does not close inputStream, you can use IOUtils.closeQuietly for that
public static String convertISToString(InputStream inputStream,String encoding){
String theString = IOUtils.toString(inputStream, encoding);
IOUtils.closeQuietly();
return theString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment