In IntelliJ IDEA , this code runs without any issues, but when I send task for validation, result is: The program ran too long and was closed!
package com.codegym.task.task18.task1801;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Scanner;
/*
Maximum byte
*/
public class Solution {
public static void main(String[] args) throws Exception {
Scanner console = new Scanner(System.in);
System.out.print("Please enter filename: ");
String fileName = console.nextLine();
try(
InputStream fStream = new FileInputStream(fileName)
) {
int maxByte = 0;
int currByte;
while((currByte = fStream.read()) != -1){
if (currByte > maxByte)
maxByte = currByte;
}
System.out.println("Max byte is: " + maxByte);
}
catch (Exception e){
throw e;
}
}
}