Добрый день!
Не проходит проверку по 4-му пункту, помогите разобраться!
Кроме, того выполнение без проверки выдает исключение - Исключение системы безопасности JavaRush. Вы выполняете потенциально опасную или запрещенную операцию
java.security.AccessControlException: access denied ("java.io.FilePermission" "com/data2.txt" "write")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkWrite(SecurityManager.java:979)
at com.javarush.task.common.model.util.SecurityManagerProxy.checkWrite(SecurityManagerProxy.java:136)
at java.io.FileOutputStream.<init>(FileOutputStream.java:200)
at java.io.FileOutputStream.<init>(FileOutputStream.java:101)
at com.javarush.task.task18.task1808.Solution.main(Solution.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.javarush.task.common.model.execution.ExecuteService.callMainMethod(ExecuteService.java:78)
at com.javarush.task.common.model.execution.ExecuteService.execute(ExecuteService.java:102)
at com.javarush.task.app.execution.ExecutionService.execute(ExecutionService.java:110)
at com.javarush.task.app.execution.ExecutionService.main(ExecutionService.java:254)
at com.javarush.task.app.MainApplication.main(MainApplication.java:49)
package com.javarush.task.task18.task1808;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.ArrayList;
/*
Разделение файла
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s1 = reader.readLine();
String s2 = reader.readLine();
String s3 = reader.readLine();
FileInputStream f1 = new FileInputStream(s1);
FileOutputStream f2 = new FileOutputStream(s2);
FileOutputStream f3 = new FileOutputStream(s3);
byte[] buffer = new byte[100];
int count = 0;
while(f1.available() > 0) {
count = f1.read(buffer);
if (count % 2 == 0) {
f2.write(buffer, 0, count / 2);
f3.write(buffer, count / 2 + 1, count / 2);
} else if (count % 2 != 0) {
f2.write(buffer, 0, count / 2 + 1);
f3.write(buffer, count / 2 + 1, count / 2);
}
}
reader.close();
f1.close();
f2.close();
f3.close();
}
}