package com.javarush.task.task18.task1823;
import java.io.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args) throws IOException, InterruptedException {
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
String Str=reader.readLine();
while(!Str.equals("exit")) {
Str=reader.readLine();
ReadThread rd = new ReadThread(Str);
rd.start();
}
reader.close();
}
public static class ReadThread extends Thread {
public String fileName;
public ReadThread(String fileName) throws IOException {
this.fileName=fileName;
}
public void run(){
HashMap<Integer, Integer> Tempmap = new HashMap<>();
try {
FileInputStream file = new FileInputStream(fileName);
while (file.available() > 0) {
int data = file.read();
Integer count = Tempmap.get(data);
Tempmap.put(data, count == null ? 1 : count + 1);
}file.close();
}
catch (FileNotFoundException e){
} catch (IOException e) {
e.printStackTrace();
}
for (Map.Entry<Integer, Integer> item : Tempmap.entrySet()) {
if (item.getValue() == Collections.max(Tempmap.values())) {//выводим Максимальное значение мапы
resultMap.put(fileName, item.getKey());
}
}
}
}
}package com.javarush.task.task18.task1823;
import java.io.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args) throws IOException, InterruptedException {
Thread t= new ReadFile();
t.run();
}
public static class ReadThread extends Thread {
public ReadThread(String fileName) throws IOException {
//implement constructor body
// System.out.println(" File Name is: "+ fileName);
HashMap<Integer, Integer> Tempmap = new HashMap<>();
FileInputStream file = new FileInputStream(fileName);
while (file.available() > 0) {
int data = file.read();
Integer count = Tempmap.get(data);
Tempmap.put(data, count == null ? 1 : count + 1);
}
file.close();
for (Map.Entry<Integer, Integer> item : Tempmap.entrySet()) {
if (item.getValue() == Collections.max(Tempmap.values())) {//выводим Максимальное значение мапы
resultMap.put(item.getKey().toString(), item.getValue());
}
}
}
// implement file reading here - реализуйте чтение из файла тут
}
public static class ReadFile extends Thread{
public void run(){
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
String Str=" ";
while(!Str.equals("exit")) {
if(Str.equals("exit")) break;
try {
new Thread(new ReadThread(Str = reader.readLine())).start();
} catch (IOException e) {
//e.printStackTrace();
}
}
}
}
}