Created
July 8, 2016 17:20
-
-
Save josinSbazin/c5022e03313f27d81e5ae4ad1dee39cc to your computer and use it in GitHub Desktop.
level18.lesson05.task03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level18.lesson05.task03; | |
/* Разделение файла | |
Считать с консоли три имени файла: файл1, файл2, файл3. | |
Разделить файл1 по следующему критерию: | |
Первую половину байт записать в файл2, вторую половину байт записать в файл3. | |
Если в файл1 количество байт нечетное, то файл2 должен содержать бОльшую часть. | |
Закрыть потоки. Не использовать try-with-resources | |
*/ | |
import java.io.*; | |
public class Solution { | |
public static void main(String[] args) throws IOException { | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
String path1 = reader.readLine(); | |
String path2 = reader.readLine(); | |
String path3 = reader.readLine(); | |
reader.close(); | |
//читаем в массив. Заметка 2147483647 - предельно возможный размер массива! | |
FileInputStream fileInputStream = new FileInputStream(path1); | |
int size = fileInputStream.available(); | |
int partSize = size/2; | |
int big = size-partSize; | |
byte[] data = new byte[size]; | |
fileInputStream.read(data); | |
fileInputStream.close(); | |
//пишем в массив | |
FileOutputStream fileOutputStream2 = new FileOutputStream(path2); | |
FileOutputStream fileOutputStream3 = new FileOutputStream(path3); | |
fileOutputStream2.write(data, 0, big); | |
fileOutputStream2.close(); | |
fileOutputStream3.write(data, big, partSize); | |
fileOutputStream3.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment