Cannot figure out mistakes in my code.
Is there someone could please help me?
package zh.codegym.task.task18.task1825;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
import java.util.*;
import java.io.*;
/*
构建文件
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
String str;
List<String> list = new ArrayList<>();
//read file name
while (!(str = console.readLine()).equals("end"))
list.add(str);
console.close();
//sort original files
Set<String> originSet = new TreeSet(list);
//replace suffix
for (String string : list)
string.replaceAll("\\.part[0-9]+", "");
//use set to remove duplicate elements
Set<String> set = new HashSet(list);
//use new name to creat file
for (String fileName : set) {
File file = new File(fileName);
FileOutputStream outStream = new FileOutputStream(file);
//read original file with same suffix into new file
for (String originName : originSet) {
//remove suffix
String temp = originName.replaceAll("\\.part[0-9]+", "");
//if original file has the same part with new file
if (temp.equals(fileName)) {
//creat inputStream and write it into the new file
FileInputStream inputStream = new FileInputStream(originName);
while (inputStream.available() > 0) {
int data = inputStream.read();
outStream.write(data);
}
//close inputStream
inputStream.close();
}
}
//close outputStream
outStream.close();
}
}
}