Добрый день
прошу помощи по задаче - код работает, валидатор не принимает
package com.javarush.task.task18.task1828;
/*
Прайсы 2
*/
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
public class Solution {
static String data = "";
static ArrayList<Integer> indexList = new ArrayList<>();
static ArrayList<String> tempList = new ArrayList<>();
static BufferedReader bufferedReader;
static FileOutputStream fileOutputStream;
static String fileName ="";
static int id, stringLength;
static int counter = 0;
static String stringLine ="";
static BufferedWriter bufferedWriter;
static PrintWriter printWriter;
static byte [] bytes = null;
// =========== удаление по id ===========================
public static void deleteByID(String id, String fileName){
File sourseFile = new File(fileName);
File tempFile = new File("C://temp.txt");
try{
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
printWriter = new PrintWriter(tempFile, "Cp1251");
while ((data = bufferedReader.readLine()) != null) {
String dataString = data.substring(0, 8).trim();
if (!(dataString.equals(id))){
tempList.add(data);
}
}
for (String d : tempList){
// System.out.println(d);
printWriter.print(d+"\n");
}
printWriter.close();
bufferedReader.close();
sourseFile.delete();
tempFile.renameTo(sourseFile);
}catch (IOException e){
e.printStackTrace();
}
}
// =============== обновление по id =========================
public static void refreshById (String id, String [] args, String fileName){
File sourseFile = new File(fileName);
File tempFile = new File("C://temp.txt");
try{
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
printWriter = new PrintWriter(tempFile, "Cp1251");
while ((data = bufferedReader.readLine()) != null) {
String dataString = data.substring(0, 8).trim();
if (!dataString.equals(id)){
tempList.add(data + "\n");
}else {
tempList.add(addSpace(args[1]).substring(0,8) + addSpace(stringCreation(args)).substring(0,30) + addSpace(args[args.length-2]).substring(0,8)+ addSpace(args[args.length-1]).substring(0,4) + "\n");
}
}
for (String d : tempList){
printWriter.print(d);
}
printWriter.close();
bufferedReader.close();
sourseFile.delete();
tempFile.renameTo(sourseFile);
}catch (IOException e){
e.printStackTrace();
}
}
// =========== составление строки названия =========================
public static String stringCreation(String [] args){
for (int i = 2; i <args.length-2 ; i++) {
stringLine += args[i]+" ";
}return stringLine;
}
// =========== добавление пробелов ========================
public static String addSpace (String st){
String space = " ";
String stringName="";
switch (counter){
case (0):{
if ((stringLength = 8 - st.length())>0){
for (int i = 0; i <stringLength ; i++) {
space+=space;
}
} stringName = st+space;
counter++;
break;
}
case (1):{
if ((stringLength = 30 - st.length())>0){
for (int i = 0; i <stringLength ; i++) {
space+=space;
}
} stringName = st+space;
counter++;
break;
}
case (2):{
if ((stringLength = 8 - st.length())>0){
for (int i = 0; i <stringLength ; i++) {
space+=space;
}
} stringName = st+space;
counter++;
break;
}
case (3):{
if ((stringLength = 8 - st.length())>0){
for (int i = 0; i <stringLength ; i++) {
space+=space;
}
} stringName = st+space;
counter=0;
break;
}
}
return stringName;
}
public static void main(String[] args) throws IOException {
String fileName = "";
String data ="";
try {
bufferedReader = new BufferedReader(new InputStreamReader(System.in));
fileName = bufferedReader.readLine();
switch (args[0]){
case ("-u"):{
refreshById(args[1], args, fileName);
break;
}
case ("-d"):{
deleteByID(args[1], fileName);
break;
}
}
System.out.println(data);
} catch (IOException e) {
e.printStackTrace();
}
finally {
bufferedReader.close();
// fileOutputStream.close();
}
}
}