Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level18.lesson10.home10;
- /* Собираем файл
- Собираем файл из кусочков
- 1. Считывать с консоли имена файлов
- Каждый файл имеет имя: [someName].partN.
- Например, Lion.avi.part1, Lion.avi.part2, ..., Lion.avi.part37.
- 2. Имена файлов подаются в произвольном порядке. Ввод заканчивается словом "end"
- В папке, где находятся все прочтенные файлы, создать файл без приставки [.partN]. Например, Lion.avi
- В него переписать все байты из файлов-частей используя буфер.
- Файлы переписывать в строгой последовательности, сначала первую часть,
- потом вторую, ..., в конце - последнюю.
- Закрыть потоки. Не использовать try-with-resources
- */
- import java.io.*;
- import java.util.*;
- public class Solution {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String fileName;
- boolean stopInput = false;
- TreeMap<Integer, String> fileList = new TreeMap<Integer, String>();
- while (!stopInput) {
- fileName =reader.readLine();
- if (fileName.equals("end")) {
- stopInput = true;
- }
- else {
- fileList.put(returnIndex(fileName),fileName);
- }
- }
- /*---------------Print file list_to delete---*/
- for (Map.Entry<Integer, String> entry : fileList.entrySet()) {
- int key = entry.getKey();
- String value = entry.getValue();
- System.out.println(key + " " + value);
- }
- /*---------------------------------------------*/
- reader.close();
- FileInputStream myResultFile = null;
- try {
- myResultFile
- }
- }
- public static int returnIndex (String someName) {
- int i = someName.lastIndexOf(".part");
- return Integer.parseInt(someName.substring(i+5));
- }
- public static File createFile (String fileName) throws IOException{
- File someFile = new File(fileName);
- if (someFile.createNewFile()) {
- }
- return someFile;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement