Hello, Mates.
And I don't know what I do wrong?
2nd req. is in line 35 and there is whole path.
3rd. req all data should be in TreeSet list ??? Or I should use a different List.
4th req. Idk they want to use byte array or BufferedInputStream or for write BufferedOutputStream?
5th req. both are closed. line 30 and 42
package pl.codegym.task.task18.task1825;
import java.io.*;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
/*
Tworzenie pliku
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String nameFile = "";
TreeSet<Integer> mySet = new TreeSet<>();
while (true)
{
nameFile = reader.readLine();
if (nameFile.equals("end")) {
break;
}
FileInputStream fileInputStream = new FileInputStream(nameFile);
byte[] inputBuffer = new byte[fileInputStream.available()];
while (fileInputStream.available() > 0) {
mySet.add(fileInputStream.read(inputBuffer));
}
fileInputStream.close();
}
String[] splitedNameFile = nameFile.split(".");
// splitedNameFile[0] should contain whole path with file name, and splitedNameFile[1] should attach an extension to name.
String newNameFile = splitedNameFile[0] + "." + splitedNameFile[1];
FileOutputStream fileOutputStream = new FileOutputStream(newNameFile);
fileOutputStream.flush();
for (Integer i : mySet) {
fileOutputStream.write(i);
}
fileOutputStream.close();
}
}