I tested it and the result seems fine, and I even deleted the last " " (space), but still can't be verified...
package com.codegym.task.task18.task1827;
/*
Prices
*/
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
Scanner scanner=new Scanner(System.in);
String name=scanner.nextLine();
InputStream file=new FileInputStream(name);
if(args.length!=0) {
BufferedReader bf = new BufferedReader(new InputStreamReader(file));
String line;
ArrayList<Integer> idList = new ArrayList<>();
ArrayList<String> lines = new ArrayList<>();
while ((line = bf.readLine()) != null) {
idList.add(getId(line));
lines.add(line);
}
file.close();
BufferedWriter bw = new BufferedWriter(new FileWriter(name));
for (String l : lines) {
bw.write(l);
bw.newLine();
}
bw.close();
int id = Collections.max(idList) + 1;
char[] ida = String.valueOf(id).toCharArray();
char[] namea = args[1].toCharArray();
char[] pricea = args[2].toCharArray();
char[] quantitya = args[3].toCharArray();
write(ida, 8, name);
write(namea, 30, name);
write(pricea, 8, name);
write(quantitya, 4, name);
}
}
public static int getId(String line) {
char[] array=line.toCharArray();
StringBuilder sb=new StringBuilder();
for (int i=0; i<8; i++) {
if (array[i]==' ') break;
sb.append(array[i]);
}
return Integer.parseInt(sb.toString());
}
public static void write(char[] chars, int n, String outname) throws IOException {
OutputStream out=new FileOutputStream(outname,true);
for (int i=0; i<chars.length; i++) {
out.write((byte)chars[i]);
}
if (chars.length<n && n!=4) {
out.write(' ');
}
out.close();
}
}