Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 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. Закрыть потоки ввода-вывода
  9. */
  10.  
  11. import java.io.*;
  12.  
  13. public class Solution {
  14. public static void main(String[] args) throws IOException {
  15. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  16. FileInputStream in = new FileInputStream(new File(reader.readLine()));
  17. FileOutputStream out = new FileOutputStream(reader.readLine());
  18. FileOutputStream out1 = new FileOutputStream(reader.readLine());
  19. int i = 0;
  20. while ( in.available() > 0){
  21. int data = in.read();
  22. i++;
  23. if(i%2 == 1)
  24. out.write(data);
  25. else
  26. out1.write(data);
  27. }
  28. in.close();
  29. out.close();
  30. out1.close();
  31.  
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement