![image.png](https://i-blog.csdnimg.cn/blog_migrate/294ee85f418133675c70ad11f200578b.png)
package io_;
import java.io.File;
public class hw02 {
public static void main(String[] args) {
File file = new File("E:\\00生活\\07超级个体\\古典·《超级个体》(完结)\\01丨职业展望(共25讲)");
System.out.println(getLen(file)/1024/1024);
}
public static long getLen(File src){
long len = 0;
File[] files = src.listFiles();
for (File file : files) {
if(file.isFile()){
len += file.length();
}else {
len += getLen(file);
}
}
return len;
}
}
作业2
![image.png](https://i-blog.csdnimg.cn/blog_migrate/0bcccaa137d78e27e011501c26cd221e.png)
package io_;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class hw03 {
public static void main(String[] args) {
File file = new File("E:\\00生活\\07超级个体\\古典·《超级个体》(完结)\\01丨职业展望(共25讲)");
HashMap<String, Integer> count = getCount(file);
System.out.println(count);
}
public static HashMap<String, Integer> getCount(File src){
int count = 0;
HashMap<String, Integer> hm = new HashMap<>();
File[] files = src.listFiles();
for (File file : files) {
if(file.isFile()){
String name = file.getName();
String[] arr = name.split("\\.");
if(arr.length > 1){
String genre = arr[arr.length - 1];
if(hm.containsKey(genre)){
Integer integer = hm.get(genre);
hm.put(genre, integer+1);
}else{
hm.put(genre, 1);
}
}
}
else{
HashMap<String, Integer> sonMap = getCount(file);
Set<Map.Entry<String, Integer>> entries = sonMap.entrySet();
for (Map.Entry<String, Integer> entry : entries) {
String key = entry.getKey();
Integer value = entry.getValue();
if(hm.containsKey(key)){
Integer integer = hm.get(key);
hm.put(key,integer + value);
}else{
hm.put(key,value);
}
}
}
}
return hm;
}
}