Java的后缀分类_怎么用JAVA实现根据文件后缀名分类文件,并且将文件复制到不同的文件夹...

更新时间:2023-06-16 06:35:46 阅读: 评论:0

财高八斗Java的后缀分类_怎么⽤JAVA实现根据⽂件后缀名分类⽂件,并且将⽂件复制到不同的⽂件夹...
import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import javax.swing.JFileChoor;public class FileDemo { public static void main(String[] args) { File sourcePath = getSourcePath(); File outputPath = getOutputPath(); handlePath(sourcePath, outputPath); } private static void handlePath(File sourcePath, File outputPath) { if (sourcePath == null || outputPath == null) return; for (File file : sourcePath.listFiles()) { if (file.isDirectory()) { handlePath(file, outputPath); } el { String fileName = Name(); if (ains(".")) { String suffix = fileName.substring(fileName.lastIndexOf('.') + 1); copy(file, new File(outputPath, suffix)); } el { copy(file, new File(outputPath, "nosuffix")); } } } } private static void copy(File sourceFile, File targetDir) { System.out.println("copying " + sourceFile); if (!ists()) { targetDir.mkdir(); } try { FileInputStream fis = new FileInputStream(sourceFile); FileOutputStream fos = new FileOutputStream(new File(targetDir, Name())); byte[] buf = new byte[102400]; int available = 0; while ((available = fis.available()) > buf.length) { ad(buf); fos.write(buf); }
e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private static File getSourcePath() { JFileChoor choor = new JFileChoor(); choor.tFileSelectionMode(JFileChoor.DIRECTORIES_ONLY); if
(choor.showOpenDialog(null) == JFileChoor.APPROVE_OPTION) { SelectedFile(); } return null; } private static File getOutputPath() { JFileChoor choor = new JFileChoor();
choor.tFileSelectionMode(JFileChoor.DIRECTORIES_ONLY); if (choor.showSaveDialog(null) ==系统崩溃
长方体图片JFileChoor.APPROVE_OPTION) { SelectedFile(); } return null; }}先选择来源⽂件夹,然后选择输出⽂件夹。
赚钱投资
然后等待即可。程序会遍历⼦⽬录。保卫胜利果实
花用英语怎么读取消
地怎么用
评论
天气英语

本文发布于:2023-06-16 06:35:46,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1040723.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:件夹   程序   选择   后缀名   分类   系统   长方体   赚钱
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图