Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hw12;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.*;
- class MyComparator implements Comparator {
- @Override
- public int compare(Object o1, Object o2) {
- int ch1 = (Integer) o1;
- int ch2 = (Integer) o2;
- if (ch1 > ch2)
- return -1;
- else {
- if (ch1 < ch2)
- return 1;
- return 0;
- }
- }
- }
- public class BinaryInput {
- public static void main(String[] args) {
- FileInputStream fin = null;
- try {
- fin = new FileInputStream("input.txt");
- } catch (FileNotFoundException ex) {
- System.out.println("Input file not found!");
- }
- ArrayList<Integer> temp = new ArrayList<Integer>();
- try {
- int i;
- do {
- i = fin.read();
- if (i != -1)
- temp.add(i);
- } while (i != -1);
- } catch (IOException ex) {
- System.out.println("Error file!");
- }
- finally{
- try{
- if(fin!=null)
- fin.close();
- }
- catch(IOException ex){
- System.out.println(ex.getMessage());
- }
- }
- TreeSet<Integer> ourbytes = new TreeSet<>(new MyComparator());
- ourbytes.addAll(temp);
- System.out.println(ourbytes);
- }
- }
Add Comment
Please, Sign In to add comment