When I use my test.txt file, instead of args[0], it seems to do what the task asks and works perfectly. However, when I replace my file with args[0] it will Time out and not verify. Any help would be appreciated. Thanks!
package com.codegym.task.task18.task1821;
/*
Symbol frequency
*/
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
public class Solution {
public static void main(String[] args) throws IOException {
try (FileInputStream inputStream = new FileInputStream(args[0])) {
TreeMap<Character, Integer> treeMap = new TreeMap<>();
int frequency = 0;
for (char i = 0; i < 256; i++) {
treeMap.put(i, frequency);
}
while (inputStream.available() > 0) {
int data = inputStream.read();
for (Character key : treeMap.keySet()) {
frequency = 0;
if (key == (char) data) {
frequency++;
treeMap.replace(key, treeMap.get(key) + frequency);
}
}
}
for (Map.Entry<Character, Integer> x : treeMap.entrySet()) {
if (x.getValue() > 0) {
System.out.println(x.getKey() + " " + x.getValue());
}
}
}
}
}