Прошу помощи. Не могу понять где ошибка, программа по 2 пункту не проходит
package com.javarush.task.pro.task15.task1504;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;
/*
Перепутанные байты
*/
public class Solution {
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in);
var inputStream = Files.newInputStream(Paths.get(scanner.nextLine()));
var outputStream = Files.newOutputStream(Paths.get(scanner.nextLine())))
{ byte[] buffer = new byte[1024];
byte[] bufferhelp = inputStream.readAllBytes();
for (int i=0; i<bufferhelp.length;i++) {
if ((i%2!=0)&&(i==bufferhelp.length-1)) {
buffer [i]=bufferhelp [i];
} else if (i%2==0) {
buffer [i]=bufferhelp [i+1];
} else if (i%2!=0) {
buffer [i]=bufferhelp [i-1]; }
outputStream.write(buffer);}
} catch (Exception e) {
System.out.println("Something went wrong : " + e);
}
}
}