一张图片用一个文件夹装,比如说有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