package com.codegym.task.task18.task1809;
/*
Reversing a file
*/
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
InputStream in = new FileInputStream(reader.readLine());
OutputStream out = new FileOutputStream(reader.readLine());
ArrayList<Integer> list = new ArrayList<>();
int tot = in.available();
byte[] byte1 = new byte[tot];
in.close();
Collections.reverse(list);
for(int i = byte1.length-1; i >= 0; i--)
out.write(byte1[i]);
out.close();
}
}
Help
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
18 April 2019, 16:01solution
#1 You didn't read anything in. At line 20 you just declare a byte[] in the length needed to read everything in, but then the next line you close the InputStream.
#2 If 'byte1' is where you are planning on storing the data read in, and 'list' is where you are planning to store the data to write; there is a problem in that you never transfer the data from one to the other.
#3 Line 23 reverses the data in 'list', then your for loop at line 24 writes the data in reverse. If you reverse it once, then reverse it twice; you end up with the data in the same order that you read it in, but a bunch of unnecessary steps to get there.
+2
Satya Vath
19 April 2019, 03:57
Thanks Guadalupe Gagnon For Your Suggestion
0