I don't uderstand even the first requirements doesn't work, it's what i use all the time
the "part" after the extension bothered me so i make a try where I remove it before use all the file name's in my FileInputStream (inside for...each), thus i sucess to create a file on my computer, in the same folder of the others file, and with thier content in the order.
String file = a.substring(0,a.indexOf(".part"));
FileInputStream fis = new FileInputStream(file);
Thanks for your helppackage fr.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.*;
/*
Création d'un fichier
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader lecteur = new BufferedReader(new InputStreamReader(System.in));
String fileName = "";
List<String> filesName = new ArrayList<>();
while (true) {
fileName = lecteur.readLine();
if (fileName.equals("fin")) break;
filesName.add(fileName);
}
lecteur.close();
String targetFile = fileName.substring(0,fileName.indexOf(".part"));
tri(filesName);
FileOutputStream outStream = new FileOutputStream(targetFile);
for (String a : filesName) {
FileInputStream fis = new FileInputStream(a);
byte[] b = new byte[fis.available()];
int c = fis.read(b);
outStream.write(b);
fis.close();
}
outStream.close();
}
private static List<String> tri(List<String> liste) {
for (int i = 0; i < liste.size(); i++) {
for ( int j = 0; j < liste.size() - 1; j++) {
String a = liste.get(j);
String b = liste.get(j+1);
int aPart = Integer.parseInt(a.substring((a.lastIndexOf(".part")+5)));
int bPart = Integer.parseInt(b.substring((b.lastIndexOf(".part")+5)));
if (aPart > bPart) {
liste.set(j,b);
liste.set(j+1,a);
}
}
}
return liste;
}
}