I understand what the task requires, however, I am not clear in the steps I should follow to convert the byte data to find the id and display the required information - as you can see from my code.
For example, int data = inputStream.read(); is going to give me bytes. It does not give me lines, characters, strings or integers. So should I turn the inputStream as a string? Break it into lines (what would be character that denotes the end of the line)?
So how do I get an inputStream into lines and how it knows it is a line? Does it have at the end of each line a return carriage?
One thing I can do is to change the int id into a byte, find it as a byte, but how do I display the rest of the elements in that line?
I hope you understand my confusion.
Thanks for your help!
package com.codegym.task.task18.task1822;
/*
Finding data inside a file
*/
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) {
int id = Integer.parseInt(args[0]);
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
FileInputStream inputStream = new FileInputStream(fileName);
while(inputStream.available()>0){
int data = inputStream.read();
if(data == id){
System.out.println(data);
}
}
inputStream.close();
}catch(Exception e){
e.printStackTrace();
}
}
}