Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level18.lesson10.home03;
- /* Два в одном
- Считать с консоли 3 имени файла
- Записать
- в первый файл содержимого второго файла,
- а потом дописать содержимое третьего файла (в первый)
- Закрыть потоки. Не использовать 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 fileName1=reader.readLine();
- String fileName2=reader.readLine();
- String fileName3=reader.readLine();
- reader.close();
- FileInputStream fileInputStream = new FileInputStream(fileName2);
- FileOutputStream fileOutputStream = new FileOutputStream(fileName1,true);
- byte[]buffer = new byte[1024];
- while (fileInputStream.available()>0) {
- int count = fileInputStream.read(buffer);
- fileOutputStream.write(buffer,0,count);
- }
- fileInputStream.close();
- fileOutputStream.close();
- FileInputStream fileInputStream2 = new FileInputStream(fileName3);
- FileOutputStream fileOutputStream2 = new FileOutputStream(fileName1,true);
- byte[]buffer2 = new byte[1024];
- while (fileInputStream2.available()>0) {
- int count = fileInputStream2.read(buffer2);
- fileOutputStream2.write(buffer2,0,count);
- }
- fileInputStream2.close();
- fileOutputStream2.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement