Why do i keep getting FileNotFoundException even though the path is correct?
package com.codegym.task.task18.task1825;
import java.io.*;
import java.util.ArrayList;
import java.util.Set;
import java.util.TreeSet;
/*
Building a file
1. The program must read file names from the console until the word "end" is entered.
2. Create a stream to write to the file without the "part" suffix (".<partN>") in the folder with all the "part" files.
3. Copy all the bytes from the *.partN files to the new file.
4. You should use a buffer for the reading and writing.
5. The file streams must be closed.
6. Don't use static variables.
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
ArrayList<String> list = new ArrayList<>();
String fileOutPut = null;
FileInputStream fileInputStream;
while(!fileName.equals("end")){
list.add(fileName);
fileName = reader.readLine();
}
for(String x : list){
if(!x.contains("part")){
fileOutPut = x;
}
}
FileOutputStream fileOutputStream = new FileOutputStream(fileOutPut,true);
//System.out.println(fileOutPut);
for(int i = 0; i < list.size()-1;i++) {
if (list.get(i).contains("part" + i+1)) {
int getIndex = list.get(i).indexOf("part" + i);
fileInputStream = new FileInputStream(list.get(getIndex));
//System.out.println(list.get(i));
byte[] listB = new byte[fileInputStream.available()];
while(fileInputStream.available() > 0) {
int read = fileInputStream.read(listB);
//byte[] writer = String.valueOf(read).getBytes();
fileOutputStream.write(listB);
}
fileInputStream.close();
fileOutputStream.close();
}
}
}
}