The output seems ok or maybe I just don't understand it.
package com.codegym.task.task18.task1822;
/*
Finding data inside a file
1. The program should read a file name from the console.
2. Create an input stream for the file.
3. The program should search the file and display information related to the specified id passed as the first argument.
4. The stream used to read the file must be closed.
C:\Users\40742\Desktop\file1.txt
*/
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file = reader.readLine();
FileInputStream inputStream = new FileInputStream(file);
BufferedReader read = new BufferedReader(new InputStreamReader(inputStream));
ArrayList<String> array = new ArrayList<>();
while(read.ready()){
array.add(read.readLine());
}
HashMap<Integer,String> map = new HashMap<>();
String [] info = array.get(0).split(" ", 0);
int id = Integer.parseInt(info[0]);
String productInfo = info[1] + " " + info[2] + " " + info[3];
map.put(id,productInfo);
SearchForProduct(map,id);
reader.close();
inputStream.close();
read.close();
}
public static void SearchForProduct (HashMap<Integer,String> hashmap, Integer id ){
for(Map.Entry<Integer, String> x : hashmap.entrySet()){
if(id.equals(x.getKey())){
System.out.println(x.getValue());
}
}
}
}