Advertisement
jaVer404

level18.lesson10.home10(beta_night build)

Jan 15th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 KB | None | 0 0
  1. package com.javarush.test.level18.lesson10.home10;
  2.  
  3. /* Собираем файл
  4. Собираем файл из кусочков
  5. 1. Считывать с консоли имена файлов
  6. Каждый файл имеет имя: [someName].partN.
  7. Например, Lion.avi.part1, Lion.avi.part2, ..., Lion.avi.part37.
  8.  
  9. 2. Имена файлов подаются в произвольном порядке. Ввод заканчивается словом "end"
  10.  
  11. В папке, где находятся все прочтенные файлы, создать файл без приставки [.partN]. Например, Lion.avi
  12. В него переписать все байты из файлов-частей используя буфер.
  13. Файлы переписывать в строгой последовательности, сначала первую часть,
  14. потом вторую, ..., в конце - последнюю.
  15.  
  16. Закрыть потоки. Не использовать try-with-resources
  17. */
  18.  
  19. import java.io.*;
  20. import java.util.*;
  21.  
  22. public class Solution {
  23.     public static void main(String[] args) throws IOException {
  24.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  25.         String fileName;
  26.         boolean stopInput = false;
  27.         TreeMap<Integer, String> fileList = new TreeMap<Integer, String>();
  28.         while (!stopInput) {
  29.             fileName =reader.readLine();
  30.             if (fileName.equals("end")) {
  31.                 stopInput = true;
  32.             }
  33.             else {
  34.                  fileList.put(returnIndex(fileName),fileName);
  35.             }
  36.         }
  37.  
  38. /*---------------Print file list_to delete---*/
  39.         for (Map.Entry<Integer, String> entry : fileList.entrySet()) {
  40.             int key = entry.getKey();
  41.             String value = entry.getValue();
  42.             System.out.println(key + " " + value);
  43.         }
  44. /*---------------------------------------------*/
  45.         reader.close();
  46.         FileInputStream myResultFile = null;
  47.  
  48.         try {
  49.             myResultFile
  50.  
  51.         }
  52.     }
  53.     public static  int returnIndex (String someName) {
  54.         int i = someName.lastIndexOf(".part");
  55.         return Integer.parseInt(someName.substring(i+5));
  56.     }
  57.  
  58.     public static File createFile (String fileName) throws IOException{
  59.         File someFile = new File(fileName);
  60.         if (someFile.createNewFile()) {
  61.         }
  62.         return someFile;
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement