Hi there,
I'm to lazy to test this on test data. Can some1 glance over this and tell give me a hint. It's almost Christmas after all =P.
Sorry for the missing comments in the code, i didn't think i'd have to ask for help on this one.
package com.codegym.task.task18.task1823;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
/*
Threads and bytes
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args) throws Exception{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String s = "";
while (true){
s = bf.readLine();
if("exit".equals(s)){
break;
}
ReadThread rt = new ReadThread(s);
rt.start();
}
bf.close();
}
public static class ReadThread extends Thread {
private String fn;
public ReadThread(String fileName) {
// Implement constructor body
this.fn = fileName;
}
// Implement file reading here
public void run() {
try {
FileInputStream fis = new FileInputStream(fn);
HashMap<Integer, Integer> temp = new HashMap();
while (fis.available() > 0) {
int a = fis.read();
int max = 1;
if (temp.containsKey(a)) {
temp.put(a, (temp.get(a) + 1));
if (temp.get(a) > max) {
max = temp.get(a);
}
} else {
temp.putIfAbsent(a, 1);
}
fis.close();
for (Map.Entry<Integer, Integer> entry : temp.entrySet()) {
if (entry.getValue() == max) {
synchronized (resultMap){
resultMap.put(fn, entry.getKey());}
}
}
}
}
catch (Exception e)
{
}
}
}
}