Валя *ука за****л . Что не так? все записывает, все добавляет. уже скопипастил несколько вариантов форматирования строки на запись.
package com.javarush.task.task18.task1827;
import java.io.*;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
String result = null;
Scanner scanner = new Scanner(System.in);
String fileName = scanner.nextLine();
scanner.close();
if(args.length!=0 && args[0].equals("-c")) {
File file = new File(fileName);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = "";
int max = 0;
int id;
while (null != (line = reader.readLine())) {
try {
id = Integer.parseInt(line.substring(0, 8).trim());
if (max < id) max = id;
} catch (Exception e) {
}
}
reader.close();
id = ++max;
result = (String.valueOf(id) + " ").substring(0, 8);
result += (args[1] + " ").substring(0, 30);
result += (args[2] + " ").substring(0, 8);
result += (args[3] + " ").substring(0, 4);}
if(result!=null){
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true));
writer.newLine();
writer.write(result);
writer.close();
}
}
}