package fileread;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
public class main {
static String dirpath = "./test.txt";
public static void main(String[] args) {
List list=new ArrayList<>();
try {
File dir = new File("D:\\desktopD\\file");
String[] children = dir.list();
for(int i=0;i<children.length;i++){
String filename=children[i];
String subname=filename.substring(0,4);
list.add(subname);
//System.out.println(subname);
}
List<String> allLines = Files.readAllLines(Paths.get("D:\\desktopD\\file\\file.txt"));
for (String line : allLines) {
System.out.println("line:"+line);
String subline=line.substring(0,4);
if(list.contains(subline)){
File oldfile=new File("D:\\desktopD\\file\\"+subline+".jpg");
File newname=new File("D:\\desktopD\\file\\"+line+".jpg");
oldfile.renameTo(newname);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}