package com.codegym.task.task18.task1823;
import java.util.HashMap;
import java.util.Map;
import java.io.*;
/*
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 reader = new BufferedReader(new InputStreamReader(System.in));
while(true){
String fileName = reader.readLine();
if(fileName.equals("exit")) break;
ReadThread rd = new ReadThread(fileName);
rd.start();
resultMap.put(fileName, rd.getFreqChar());
}
}
public static class ReadThread extends Thread {
private String fileName;
private Integer freqChar;
public ReadThread(String fileName) {
this.fileName = fileName;
// Implement constructor body
}
// Implement file reading here
public Integer getFreqChar(){
return this.freqChar;
}
public void run(){
try{
FileInputStream fileInputStream = new FileInputStream(this.fileName);
HashMap<Integer, Integer> map = new HashMap<>();
while(fileInputStream.available() > 0){
int data = fileInputStream.read();
if(map.containsKey(data)){
map.put(data, map.get(data)+1);
}
else{
map.put(data, 1);
}
}
fileInputStream.close();
int freq = -1;
int freqCharThread = 0;
for (Map.Entry<Integer, Integer> entry : map.entrySet()){
if(entry.getValue() > freq){
freq = entry.getValue();
freqCharThread = entry.getKey();
}
}
this.freqChar = freqCharThread;
}catch(Exception e){}
}
}
}
package com.codegym.task.task18.task1823;
import java.util.HashMap;
import java.util.Map;
import java.io.*;
/*
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 reader = new BufferedReader(new InputStreamReader(System.in));
while(true){
String fileName = reader.readLine();
if(fileName.equals("exit")) break;
ReadThread rd = new ReadThread(fileName);
rd.start();
resultMap.put(fileName, rd.getFreqChar());
// resultMap.put(fileName, rd.find());
}
}
public static class ReadThread extends Thread {
private String fileName;
private Integer freqChar;
public ReadThread(String fileName) {
this.fileName = fileName;
// Implement constructor body
}
// Implement file reading here
public Integer getFreqChar(){
return this.freqChar;
}
public void run(){
try{
// public Integer find() throws Exception{
FileInputStream fileInputStream = new FileInputStream(this.fileName);
HashMap<Integer, Integer> map = new HashMap<>();
while(fileInputStream.available() > 0){
int data = fileInputStream.read();
if(map.containsKey(data)){
map.put(data, map.get(data)+1);
}
else{
map.put(data, 1);
}
}
fileInputStream.close();
int freq = -1;
int freqCharThread = 0;
for (Map.Entry<Integer, Integer> entry : map.entrySet()){
if(entry.getValue() > freq){
freq = entry.getValue();
freqCharThread = entry.getKey();
}
}
this.freqChar = freqCharThread;
}catch(Exception e){}
// return freqCharThread;
}
}
}