It's not reversing the bytes but i've done everything correct but where is the problem
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
FileInputStream fis = new FileInputStream(br.readLine());
FileOutputStream fis1 = new FileOutputStream(br.readLine());
List<Byte> list = new LinkedList<>();
byte[] fuldata = new byte[fis.available()];
int data = fis.read(fuldata);
list.add((byte)data);
Collections.reverse(list);
for(Byte n : list){
fis1.write(n);
}
fis1.close();
fis.close();
need help with Collections
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
dhanush
12 August 2020, 14:16
Thank you it worked.
I already finished the task but while doing with Collections it's not verifying with your suggestion i understand how it works with Collection when i use list.add(Bytes.asList(fuldata));
It shows an error of argument mismatch then i used the for each loop to add the data and reverse the list it worked.
0
Guadalupe Gagnon
12 August 2020, 13:57solution
Always remember that computers will only do EXACTLY what you, as the programmer, tell them to do. This means that (except maybe 1 time in a billion), the problem is something that you are overlooking. I would consider adding each byte in 'fuldata' to the list instead of the single int 'data'.
+2