javaIO流应用——通过【字节流】拷贝文件
??????? ??????? ??????? ??????????? ??????? ????????????????
发布日期:2021-04-30 21:04:33
浏览次数:97
分类:精选文章
本文共 1943 字,大约阅读时间需要 6 分钟。
??????????????????????
????
?????????????????????????????????????????????????????????????????????????????
????
??????????????????????
package com.lut.ui;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;public class FileCopy { public static void main(String[] args) { File sourceDir = new File("C:/Users/DELL/Desktop/12"); // ?????? File targetDir = new File("C:/Users/DELL/Desktop/23"); // ??????? File[] files = sourceDir.listFiles(); // ?????????????? for (File file : files) { if (file.isFile()) { // ????? try { File targetType = new File(targetDir, file.getName()); // ?????? FileInputStream inputStream = new FileInputStream(file); FileOutputStream outputStream = new FileOutputStream(targetType); byte[] buffer = new byte[1024]; int readBytes; while ((readBytes = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, readBytes); } outputStream.flush(); inputStream.close(); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } System.out.println("??????"); }} ????
sourceDir ? targetDir ???????????????listFiles() ??????????????????if (file.isFile()) ???????????????FileInputStream ????????FileOutputStream ???????byte[] buffer ?????????????????try-catch ?????????????????????
- ?????????????????????????????
- ??????????????????????????????
- ????????????????????????????????????
?????????????????????????????????????????????????
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2026年06月13日 23时37分09秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!