-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
80 lines (59 loc) · 2.6 KB
/
Solution.java
File metadata and controls
80 lines (59 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//that they may all be one; even as you, Father, are in me, and I in you, that they also may be one in us; that the world may believe that you sent me (John 17:21)
package com.javarush.task.task18.task1806;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/*
Исправить ошибки
*/
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();
}
}
/*
Исправить ошибки
Исправить функциональность в соответствии с требованиями.
Программа должна:
1. Переписать все байты одного файла в другой одним куском.
2. Закрывать потоки ввода-вывода.
Подсказка:
4 ошибки.
Требования:
1. Программа должна использовать классы FileInputStream и FileOutputStream.
2. Программа должна переписать все байты одного файла в другой одним куском.
3. Потоки FileInputStream и FileOutputStream должны быть закрыты.
4. Нужно исправить 4 ошибки.
package com.javarush.task.task18.task1806;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
*
Исправить ошибки
*
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.read() >= 0) {
//читаем весь файл одним куском
byte[] buffer = new byte[inputStream.available()];
int count = inputStream.read(buffer);
outputStream.write(buffer, 0, count);
}
inputStream.reset();
outputStream.flush();
}
}
*/