Тестировал, вроде бы всё корректно работает.
Почему валидатор не принимает решение?
package com.javarush.task.task18.task1828;
/*
Прайсы 2
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Solution {
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader ( new InputStreamReader ( System.in ) );
String path = reader.readLine ();
reader.close ();
if (args.length != 0) {
switch (args[0]) {
case "-u":
Stream<String> lines = Files.lines ( Paths.get ( path ) );
List<String> replaced = lines.collect ( Collectors.toList () );
for (String s : replaced) {
if (s.substring ( 0,8 ).replaceAll ( "\\D","" ).equals ( args[1] )) {
replaced.set ( replaced.indexOf ( s ), String.format ( "%-8.8s%-30.30s%-8.8s%-4.4s", args[1], args[2], args[3], args[4] ) );
}
}
Files.write ( Paths.get ( path ), replaced );
lines.close ();
break;
case "-d":
Stream<String> linesDel = Files.lines ( Paths.get ( path ) );
List<String> deleted = linesDel.collect ( Collectors.toList () );
Iterator iterator = deleted.iterator ();
while (iterator.hasNext ()) {
String s = (String) iterator.next ();
if (s.substring ( 0,8 ).replaceAll ( "\\D","" ).equals ( args[1] )) {
iterator.remove ();
}
}
Files.write ( Paths.get ( path ), deleted );
linesDel.close ();
break;
default:
break;
}
}
} catch (IOException e) {}
}
}