一张图片用一个文件夹装,比如说有100张图片,就自动创建100个文件夹,每个文件夹装一张图片,这功能要怎么实现?
1条回答 默认 最新
- Jerome_Song 2013-12-10 13:01关注
java代码可以吗,就这么个逻辑 shell或python应该更简单
public static void main(String[] args) { File file = new java.io.File("/home/jerome/Pictures"); file.getAbsoluteFile(); String[] files = file.list(); for (String string : files) { System.out.println(string); File dir = new File(file.getAbsolutePath() + "/" + string.substring(0, string.lastIndexOf("."))); dir.mkdir(); copyFile(file+"/"+string, dir.getAbsolutePath()+"/"+string); delFile(file+"/"+string); } } public static void delFile(String filePathAndName) { try { String filePath = filePathAndName; filePath = filePath.toString(); java.io.File myDelFile = new java.io.File(filePath); myDelFile.delete(); } catch (Exception e) { e.printStackTrace(); } } public static void copyFile(String oldPath, String newPath) { try { int bytesum = 0; int byteread = 0; File oldfile = new File(oldPath); if (oldfile.exists()) { InputStream inStream = new FileInputStream(oldPath); FileOutputStream fs = new FileOutputStream(newPath); byte[] buffer = new byte[1444]; while ( (byteread = inStream.read(buffer)) != -1) { bytesum += byteread; fs.write(buffer, 0, byteread); } inStream.close(); } } catch (Exception e) { e.printStackTrace(); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 1
悬赏问题
- ¥15 C++ 头文件/宏冲突问题解决
- ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
- ¥50 安卓adb backup备份子用户应用数据失败
- ¥20 有人能用聚类分析帮我分析一下文本内容嘛
- ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
- ¥30 python代码,帮调试
- ¥15 #MATLAB仿真#车辆换道路径规划
- ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
- ¥15 数据可视化Python
- ¥15 要给毕业设计添加扫码登录的功能!!有偿