Этим методом решены две предыдущие задачи. public static void main(String[] args) throws Exception { BufferedReader buff=new BufferedReader(new InputStreamReader(System.in)); String filename=buff.readLine(); //filename="/storage/emulated/0/DCIM/1.txt"; FileInputStream is=new FileInputStream(filename); List<Byte> list=new ArrayList<>(); while(is.available()>0){ list.add((byte)is.read()); } Collections.sort(list); int[][] array=new int[256][2]; Byte earlyer=list.get(0); int count=0,mapCount=0; for(Byte byt:list){ if(earlyer.equals(byt)){ count++; }else{ earlyer=byt;mapCount++; count=1; } array[mapCount][1]=earlyer; array[mapCount][0]=count; } for(int k=0;k<array.length-230;k++){ if(array[k][0]!=0) System.out.print( array[k][1]+" "); } is.close(); }