Advertisement
Guest User

Untitled

a guest
May 31st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. package com.javarush.test.level18.lesson05.task03;
  2.  
  3. /* Разделение файла
  4. Считать с консоли три имени файла: файл1, файл2, файл3.
  5. Разделить файл1 по следующему критерию:
  6. Первую половину байт записать в файл2, вторую половину байт записать в файл3.
  7. Если в файл1 количество байт нечетное, то файл2 должен содержать бОльшую часть.
  8. Закрыть потоки. Не использовать try-with-resources
  9. */
  10. import java.io.*;
  11.  
  12. public class Solution {
  13. public static void main(String[] args) throws IOException {
  14. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  15. FileInputStream inputStream = new FileInputStream(reader.readLine());
  16. FileOutputStream outputStream1 = new FileOutputStream(reader.readLine());
  17. FileOutputStream oututStream2 = new FileOutputStream(reader.readLine());
  18.  
  19. byte[] buff = new byte[inputStream.available()];
  20. if (inputStream.available() > 0) {
  21. int count = inputStream.read(buff);
  22. if(count % 2 == 0){
  23. outputStream1.write(buff, 0, count / 2);
  24. oututStream2.write(buff, count / 2, count / 2);
  25. }
  26. else {
  27. outputStream1.write(buff, 0, count / 2+1);
  28. oututStream2.write(buff, count / 2 + 1, count / 2);
  29. }
  30. }
  31.  
  32. reader.close();
  33. inputStream.close();
  34. outputStream1.close();
  35. oututStream2.close();
  36.  
  37.  
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement