No idea why I fail the test.
I saw the solution but it doesn't make any sense.
1) they do not close the stream
2) And I don't see what is wrong with my code as the only difference is that they add if(total != 0;
package com.codegym.task.task18.task1817;
/*
Spaces
*/
import java.io.FileInputStream;
import java.io.IOException;
public class Solution {
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream(args[0]);
int countTotal = 0;
int countSpaces = 0;
while(fileInputStream.available() > 0) {
int a = fileInputStream.read();
countTotal++;
if(a == 32) countSpaces++;
}
fileInputStream.close();
double ratio = countSpaces / countTotal * 100.0;
System.out.printf("%.2f", ratio);
}
}