Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package com.javarush.task.task18.task1825;
  2.  
  3. /*
  4. Собираем файл
  5. */
  6.  
  7. import java.io.*;
  8. import java.util.ArrayList;
  9. import java.util.Collections;
  10.  
  11. /*
  12. c:/tmp/fileTest.txt.part1
  13. c:/tmp/fileTest.txt.part3
  14. c:/tmp/fileTest.txt.part5
  15. c:/tmp/fileTest.txt.part4
  16. c:/tmp/fileTest.txt.part2
  17. end
  18. */
  19. public class Solution
  20. {
  21. public static void main(String[] args) throws IOException
  22. {
  23. BufferedReader reader = new BufferedReader (new InputStreamReader (System.in));
  24. String name;
  25. ArrayList<String> list = new ArrayList<> ( );
  26. while (!(name = reader.readLine ( )).contains ("end"))
  27. {
  28. list.add (name);
  29. }
  30. Collections.sort (list);
  31. String nameNewFile = list.get (0);
  32. int pos=nameNewFile.lastIndexOf (".");
  33. nameNewFile = nameNewFile.substring (0, pos);
  34. FileOutputStream outputStream = new FileOutputStream (nameNewFile);
  35. byte[] buffer=new byte[1024];
  36. for (String nameFilePart : list)
  37. {
  38. FileInputStream inputStream = new FileInputStream (nameFilePart);
  39. while (inputStream.available ( ) > 0)
  40. { int count = inputStream.read (buffer);
  41. outputStream.write (buffer, 0, count);
  42. }
  43. inputStream.close ( );
  44. }
  45. outputStream.close ();
  46. reader.close ( );
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement