Last active
January 13, 2016 15:50
-
-
Save maoruibin/f41251d3845daddca131 to your computer and use it in GitHub Desktop.
method of copy file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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