Строки почему-то не обновляются. Хотела сделать debug, чтобы разобраться в чем дело, а он тоже не запускается. Выдаёт такую ошибку:
"C:\Program Files\AdoptOpenJDK\jdk-16.0.0.36-hotspot\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:59537,suspend=y,server=n -javaagent:C:\Users\annaa\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\211.7628.21\plugins\java\lib\rt\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath C:\Users\annaa\IdeaProjects\JavaRushTasks\out\production\2.JavaCore;C:\Users\annaa\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\211.7628.21\lib\idea_rt.jar com.javarush.task.task18.task1828.Solution -u 12890159 платье 2000 1
Connected to the target VM, address: '127.0.0.1:59537', transport: 'socket'
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
D:\\fileShop.txt
Disconnected from the target VM, address: '127.0.0.1:59537', transport: 'socket'
Process finished with exit code 0
В чём причина и как заставить debug работать?package com.javarush.task.task18.task1828;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/*
Прайсы 2
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader readerBuf = new BufferedReader(new InputStreamReader(System.in));
String fileName = readerBuf.readLine();
readerBuf.close();
//String fileName="D:\\fileShop.txt";
if (args.length == 0) return;
ArrayList<Product> products = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
while (reader.ready()) {
products.add(getProduct(reader.readLine()));
}
}
switch (args[0]) {
case "-u": {
int id = Integer.parseInt(args[1].trim());
String name = "";
for (int i = 1; i < args.length - 2; i++) {
name += args[i] + " ";
}
if (name.length() > 30) {
name = name.substring(0, 30);
}
String price = args[args.length - 2];
if (price.length() > 8) {
price = price.substring(0, 8);
}
String quantity = args[args.length - 1];
if (quantity.length() > 4) {
quantity = quantity.substring(0, 4);
}
Product product = null;
//int index=0;
for (Product currentProduct : products) {
if (currentProduct.id == id) {
product = currentProduct;
break;
}
}
if (product != null) {
product.name = name;
product.price = price;
product.quantity = quantity;
}
break;
}
case "-d": {
int id2 = Integer.parseInt(args[1].trim());
int index2 = 0;
for (int i = 0; i < products.size(); i++) {
if (products.get(i).id == id2) {
index2 = i;
break;
}
}
products.remove(index2);
}
try (FileWriter writer = new FileWriter(fileName)) {
for (Product currentProduct : products) {
writer.write(currentProduct.toString());
writer.write("\n");
}
}
}
}
public static class Product {
public int id;
public String name;
public String price;
public String quantity;
public Product(int id, String name, String price, String quantity) {
this.id = id;
this.name = name;
this.price = price;
this.quantity = quantity;
}
public Product() {
}
public String toString() {
return String.format("%-8d%-30s%-8s%-4s", this.id,this.name,this.price,this.quantity);
}
}
public static Product getProduct(String str) {
int id=Integer.parseInt(str.substring(0,8).trim());
String name=str.substring(8,38);
String price=str.substring(38,46);
String quantity=str.substring(46,50);
return new Product(id,name,price,quantity);
}
}