-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
66 lines (45 loc) · 2.04 KB
/
Solution.java
File metadata and controls
66 lines (45 loc) · 2.04 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
//Father, I desire that they also whom you have given me be with me where I am, that they may see my glory, which you have given me, for you loved me before the foundation of the world. (John 17:24)
package com.javarush.task.task18.task1809;
/*
Реверс файла
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String fileNameA = br.readLine();
String fileNameB = br.readLine();
FileInputStream fileInputStream = new FileInputStream(fileNameA);
FileOutputStream fileOutputStream = new FileOutputStream(fileNameB);
while (fileInputStream.available() > 0) {
byte[] buff = new byte[fileInputStream.available()];
byte[] reverseBuff = new byte[buff.length];
fileInputStream.read(buff);
for (int i = buff.length - 1; i >= 0; i--)
reverseBuff[buff.length - i - 1] = buff[i];
fileOutputStream.write(reverseBuff);
}
fileInputStream.close();
fileOutputStream.close();
br.close();
}
}
/*
Реверс файла
Считать с консоли 2 имени файла: файл1, файл2.
Записать в файл2 все байты из файл1, но в обратном порядке.
Закрыть потоки.
Требования:
1. Программа должна два раза считать имена файлов с консоли.
2. Для чтения из файла используй поток FileInputStream, для записи в файл - FileOutputStream
3. Во второй файл нужно записать все байты из первого в обратном порядке.
4. Потоки FileInputStream и FileOutputStream должны быть закрыты.
package com.javarush.task.task18.task1809;
/*
Реверс файла
*/
public class Solution {
public static void main(String[] args) {
}
}
*/