Hello Mates,
Because that byte. Byte has always 1.
So if my file consists of bytes, then it looks like "house of bricks".
File is house.
Byte is like brick. = [1]
House = [1][1][1][1][1][1][1][1][1][1]
So there is Requirements:
"Program powinien wyświetlać maksymalną liczbę bajtów odczytaną z pliku."
trans. "The program should display the maximum number of bytes read from the file."
For me it looks like a sum. My thinking way take it like sum.
But one Mate trying help other student suggest that solution.
while (fileReader.available() > 0) {
int current = fileReader.read();
if (current > max)
{
max = current;
}
}
And that example for me is like: There is no bigger brick, everyone brick has always 1. First or last brick always have 1 byte. There is no max, each brick is the same.
Where I do mistake? package pl.codegym.task.task18.task1801;
import java.io.FileInputStream;
import java.util.Scanner;
/*
Maksymalna liczba bajtów
*/
public class Solution {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
String fileToRead = scanner.nextLine();
FileInputStream myReadFile = new FileInputStream(fileToRead);
int sum = 0;
while(myReadFile.available() > 0) {
sum += myReadFile.read();
}
myReadFile.close();
System.out.println(sum);
}
}