package com.javarush.task.task18.task1823;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file = null;
//ReadThread readThread;
while(true){
file = reader.readLine();
if(!(file.equals("exit"))){
ReadThread thread = new ReadThread(file);
thread.start();
}else
break;
}
reader.close();
}
public static class ReadThread extends Thread {
String fileName;
public ReadThread(String fileName) throws IOException {
//implement constructor body
super();
this.fileName = fileName;
}
public void run(){
try {
ArrayList<Integer> list2 = new ArrayList<>();
FileInputStream fileInputStream = new FileInputStream(fileName);
fileInputStream.close();
Map<Integer, Integer> map = new HashMap<>();
while (fileInputStream.available() > 0) {
int n = fileInputStream.read();
list2.add(n);
}
int count=0;
int n = 0;
int element=0;
for(int i = 0; i<list2.size();i++){
for(int j=0;j<list2.size();j++){
if(list2.get(i).equals(list2.get(j))){
count++;
}
}
if(count>n){
n = count;
element = list2.get(i);
}
count=0;
}
fileInputStream.close();
resultMap.put(fileName, element);
}catch (Exception e){
e.printStackTrace();
}
}
// implement file reading here - реализуйте чтение из файла тут
}
}
package com.javarush.task.task18.task1823;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file = reader.readLine();
//ReadThread readThread;
while(true){
String str = reader.readLine();
if(str.equals("exit"))break;
new ReadThread(file).start();
}
reader.close();
}
public static class ReadThread extends Thread {
String fileName;
public ReadThread(String fileName) throws IOException {
//implement constructor body
this.fileName = fileName;
}
public void run(){
try {
ArrayList<Integer> list2 = new ArrayList<>();
FileInputStream fileInputStream = new FileInputStream(fileName);
fileInputStream.close();
Map<Integer, Integer> map = new HashMap<>();
while (fileInputStream.available() > 0) {
int n = fileInputStream.read();
list2.add(n);
}
int count=0;
int n = 0;
int element=0;
for(int i = 0; i<list2.size();i++){
for(int j=0;j<list2.size();j++){
if(list2.get(i).equals(list2.get(j))){
count++;
}
}
if(count>n){
n = count;
element = list2.get(i);
}
count=0;
}
fileInputStream.close();
resultMap.put(fileName, element);
}catch (Exception e){
e.printStackTrace();
}
}
// implement file reading here - реализуйте чтение из файла тут
}
}