Alright, bascially I noticed I'm not the only one person having weird verification problems with this task.
Please guys, tell me the ... is wrong. You can test out my code, works like a charm.
package com.codegym.task.task18.task1828;
/*
Prices 2
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws IOException {
ArrayList<String> fileLines = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
String fileName = scanner.nextLine();
Scanner fileScanner = new Scanner(new File(fileName));
while(fileScanner.hasNext()) {
fileLines.add(fileScanner.nextLine());
}
FileOutputStream outputStream = new FileOutputStream(fileName);
if(args[0].equals("-u")){
int updateId = Integer.parseInt(args[1]);
for(String line : fileLines){
try {
if(line.substring(0, 8).trim().equals(String.valueOf(updateId))) {
String updateLine = numeralCorrector(8, String.valueOf(updateId))
+ numeralCorrector(30, args[2])
+ numeralCorrector(8, args[3])
+ numeralCorrector(4, args[4]);
outputStream.write(updateLine.getBytes());
} else {
outputStream.write(line.getBytes());
}
outputStream.write(System.lineSeparator().getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}
if(args[0].equals("-d")) {
int deleteId = Integer.parseInt(args[1]);
for(String line : fileLines){
try {
if(!line.substring(0, 8).trim().equals(String.valueOf(deleteId))){
outputStream.write(line.getBytes());
outputStream.write(System.lineSeparator().getBytes());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
outputStream.close();
scanner.close();
fileScanner.close();
}
private static String numeralCorrector(int length, String word) {
StringBuilder wordBuilder = new StringBuilder(word);
while(wordBuilder.length() != length){
wordBuilder.append(" ");
}
return wordBuilder.toString();
}
// C:\Users\dell\Desktop\test.txt
}