Created
July 8, 2016 17:19
-
-
Save josinSbazin/151adfb7e1a2f9639309d288e0394b33 to your computer and use it in GitHub Desktop.
level18.lesson05.task01
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.task01; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
/* Исправить ошибки | |
Исправить функциональность в соответствии с требованиями | |
Программа должна: | |
1. переписать все байты одного файла в другой одним куском. | |
2. закрывать потоки ввода-вывода | |
Подсказка: 4 ошибки | |
*/ | |
public class Solution { | |
public static void main(String[] args) throws IOException { | |
FileInputStream inputStream = new FileInputStream("c:/data.txt"); | |
// Создаем поток-записи-байт-в-файл | |
FileOutputStream outputStream = new FileOutputStream("c:/result.txt"); | |
if (inputStream.available() > 0) { | |
//читаем весь файл одним куском | |
byte[] buffer = new byte[inputStream.available()]; | |
int count = inputStream.read(buffer); | |
outputStream.write(buffer, 0, count); | |
} | |
inputStream.close(); | |
outputStream.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment