codisinmyvines

bytevvod

Dec 23rd, 2021 (edited)
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. package hw12;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.util.*;
  7.  
  8. class MyComparator implements Comparator {
  9.  
  10. @Override
  11. public int compare(Object o1, Object o2) {
  12. int ch1 = (Integer) o1;
  13. int ch2 = (Integer) o2;
  14. if (ch1 > ch2)
  15. return -1;
  16. else {
  17. if (ch1 < ch2)
  18. return 1;
  19. return 0;
  20. }
  21. }
  22. }
  23.  
  24. public class BinaryInput {
  25. public static void main(String[] args) {
  26. FileInputStream fin = null;
  27. try {
  28. fin = new FileInputStream("input.txt");
  29. } catch (FileNotFoundException ex) {
  30. System.out.println("Input file not found!");
  31. }
  32. ArrayList<Integer> temp = new ArrayList<Integer>();
  33. try {
  34. int i;
  35. do {
  36. i = fin.read();
  37. if (i != -1)
  38. temp.add(i);
  39. } while (i != -1);
  40. } catch (IOException ex) {
  41. System.out.println("Error file!");
  42. }
  43. finally{
  44. try{
  45. if(fin!=null)
  46. fin.close();
  47. }
  48. catch(IOException ex){
  49.  
  50. System.out.println(ex.getMessage());
  51. }
  52. }
  53. TreeSet<Integer> ourbytes = new TreeSet<>(new MyComparator());
  54. ourbytes.addAll(temp);
  55. System.out.println(ourbytes);
  56. }
  57. }
  58.  
Add Comment
Please, Sign In to add comment