Подскажите почему в моем случаи трим не удаляет пробелы?
package com.javarush.task.task18.task1828;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
Прайсы 2
*/
public class Solution {
private static List<Product> productList = new ArrayList<>();
private static String path;
public static void main(String[] args) {
if (args.length == 0) {
return;
}
path = new Scanner(System.in).nextLine();
readerProduct();
switch (args[0]) {
case "-u":
try {
for (Product prod : productList) {
if (prod.getId() == Integer.parseInt(args[1])) {
prod.setProductName(args[2]);
prod.setPrice(Double.parseDouble(args[3]));
prod.setQuantity(Integer.parseInt(args[4]));
}
}
} catch (NullPointerException exception) {
System.out.println("Данные введены не верно");
}
case "-d":
for (Product prod : productList) {
try {
if (Integer.parseInt(args[1]) == prod.getId()) {
productList.remove(productList.indexOf(prod));
break;
}
} catch (NullPointerException exception) {
System.out.println("Введен не верный ИД " + prod.getId());
}
}
}
writeProducts();
}
public static void writeProducts() {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(path))) {
for (Product prod : productList
) {
writer.write(prod.toString());
}
} catch (IOException exception) {
exception.printStackTrace();
}
}
public static void readerProduct() {
try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
String prod;
while (reader.ready()) {
prod = reader.readLine();
productList.add(new Product(Integer.parseInt(prod.substring(0, 7).trim()),
prod.substring(7, 36).trim(), Double.parseDouble(prod.substring(36, 44).trim()),
Integer.parseInt(prod.substring(44).trim())));
}
} catch (IOException exception) {
exception.printStackTrace();
}
}
public static class Product {
private long id;
private String productName;
private Double price;
private int quantity;
public Product(long id, String productName, Double price, int quantity) {
this.id = id;
this.productName = productName;
this.price = price;
this.quantity = quantity;
}
public void setId(long id) {
this.id = id;
}
public void setProductName(String productName) {
this.productName = productName;
}
public void setPrice(Double price) {
this.price = price;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public long getId() {
return id;
}
public String getProductName() {
return productName;
}
public Double getPrice() {
return price;
}
public int getQuantity() {
return quantity;
}
@Override
public String toString() {
return String.format("%8d %30s %6.2f %4d"
, getId(), getProductName(), getPrice(), getQuantity());
}
}
}