package com.javarush.task.task18.task1822;
/*
Поиск данных внутри файла
*/
import javax.swing.plaf.basic.BasicButtonUI;
import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine();
File file = new File(s);
reader.close();
FileInputStream filereader = new FileInputStream(file);
String text = "";
while (filereader.available() > 0){
text = text + (char)filereader.read();
}
filereader.close();
String[] stroka = text.split("\r\n");
ArrayList<Integer> id = new ArrayList<>();
ArrayList<String> productName = new ArrayList<>();
ArrayList<Double> price = new ArrayList<>();
ArrayList<Integer> quantity = new ArrayList<>();
for(String st : stroka){
id.add(Integer.parseInt(st.split(" ")[0]));
productName.add(st.split(" ")[1]);
price.add(Double.parseDouble(st.split(" ")[2]));
quantity.add(Integer.parseInt(st.split(" ")[3]));
}
int index = id.indexOf(Integer.parseInt(args[0]));
System.out.println(id.get(index) + " " + productName.get(index) + " " + price.get(index) + " " + quantity.get(index));
}
}
package com.javarush.task.task18.task1822;
/*
Поиск данных внутри файла
*/
import javax.swing.plaf.basic.BasicButtonUI;
import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine();
File file = new File(s);
reader.close();
FileInputStream filereader = new FileInputStream(file);
String text = "";
while (filereader.available() > 0){
text = text + (char)filereader.read();
}
filereader.close();
String[] stroka = text.split("\r\n");
ArrayList<Integer> id = new ArrayList<>();
ArrayList<String> productName = new ArrayList<>();
ArrayList<Double> price = new ArrayList<>();
ArrayList<Integer> quantity = new ArrayList<>();
for(String st : stroka){
id.add(Integer.parseInt(st.split(" ")[0]));
productName.add(st.split(" ")[1]);
price.add(Double.parseDouble(st.split(" ")[2]));
quantity.add(Integer.parseInt(st.split(" ")[3]));
}
int index = id.indexOf(Integer.parseInt(args[0]));
System.out.println(id.get(index) + " " + productName.get(index) + " " + price.get(index) + " " + quantity.get(index));
}
}