Java???????????????
???????????? ???????[ 2016/9/14 10:21:14 ] ??????????????????? Java
????java?????????????
???????????Reader/Writer ???????InputStream/OutputStream
?????????????????????????????????????????????????????????????????????????????????????????????
???????java.io.File?е????
????public static void copyByFileStreams(File source?? File dest){
????FileInputStream inputStream = null;
????FileOutputStream outputStream = null;
????try{
????inputStream = new FileInputStream(source);
????outputStream = new FileOutputStream(dest);
????//??????????棬???????д??
????//byte[] b = new byte[(int)source.length()];
????//inputStream.read(b);
????//outputStream.write(b);
????//?????д
????int len = 0;
????while((len = inputStream.read(b)) != -1){
????outputStream.write(len);
????}
????}catch (IOException e) {
????e.printStackTrace();
????} finally {
????try {
????if (inputStream != null) {
????inputStream.close();
????}
????if (outputStream != null) {
????outputStream.close();
????}
????} catch (IOException e) {
????e.printStackTrace();
????}
????}
????}
???????java.nio.Channels?е????
????public static void copyByFileChannels(File source?? File dest) {
????FileInputStream inputStream = null;
????FileOutputStream outputStream = null;
????try {
????inputStream = new FileInputStream(source);
????outputStream = new FileOutputStream(dest);
????FileChannel inputChannel = inputStream.getChannel();
????FileChannel outputChannel = outputStream.getChannel();
????outputChannel.transferFrom(inputChannel?? 0?? inputChannel.size());
????} catch (IOException e) {
????e.printStackTrace();
????} finally {
????try {
????if (inputStream != null) {
????inputStream.close();
????}
????if (outputStream != null) {
????outputStream.close();
????}
????} catch (IOException e) {
????e.printStackTrace();
????}
????}
????}
???????Java7??Files.copy??????
????/**
????* ???java7??Files.copy???????????????????????FileChannels
????* @param source
????* @param dest
????*/
????public static void copyByJava7Files(File source?? File dest) {
????try {
????Files.copy(source.toPath()??dest.toPath());
????} catch (IOException e) {
????e.printStackTrace();
????}
????}
???????????????????????????????????FileChannelЧ????????????????????????????ü??????????????????ɡ?^_^
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11