я пока не уверен в правильности решения от слова совсем, но у меня не получается компиляция по причине ошибки
Ошибка в файле com/javarush/task/task18/task1828/Solution.java в строке : 60
Не найден метод "of(java.lang.String)" в интерфейсе "java.nio.file.Path"
как можно обойти подобное ?
package com.javarush.task.task18.task1828;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
/*
Прайсы 2
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader= new BufferedReader(new InputStreamReader(System.in));
/*
1- check whether the amount of args is mot smaller than 4
*/
String filename = reader.readLine();
/*BufferedReader fileReader = new BufferedReader(new FileReader(filename));
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(filename));*/
File file = new File(filename);
if(args.length ==2 || args.length==4) {
try {
/*
-Get a list of Ids
-check if id that is given as args[1] is present in the list
send the request as a function
*/
ArrayList<Integer> idList=getIds(file);
switch (args.length) {
case (2):{
if(args[0].equals("-d") && idList.contains(Integer.parseInt(args[1]))){
delete (filename,Integer.parseInt(args[1]));
} else return;
break;
}
case (4) :{
if(args[0].equals("-u")&& idList.contains(Integer.parseInt(args[1]))){
update(filename,Integer.parseInt(args[1]), args[2], Float.parseFloat(args[3]),Integer.parseInt(args[4]));
}
else return;
break;
}
}
}
catch (Exception e){
e.printStackTrace();
}
}
else return;
reader.close();
}
public static void delete(String filename ,int id) {
try {
String lineToRemove = String.valueOf(id);
List<String>lines = Files.readAllLines(Path.of(filename), StandardCharsets.UTF_8);
int lineId=0;
for (int i =0; i < lines.size(); i++){
if(lines.get(i).equals(lineToRemove)){
lineId=i;
}
}
lines.remove(lineId);
Files.write(Path.of(filename),lines, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void update(String filename, int id, String productname, float price, int quantity){
String updatedItem= String.format(System.lineSeparator()+"%-8d%-30.30s%-8.2f%-4d",id,productname,price,quantity);
try{
List<String>lines = Files.readAllLines(Path.of(filename), StandardCharsets.UTF_8);
int lineToModify = 0;
int i =0;
for (String x: lines){
if (x.substring(0,7).equals(String.valueOf(id))){
lineToModify=i;
}
i++;
}
lines.set(lineToModify,updatedItem);
Files.write(Path.of(filename),lines, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
}
public static ArrayList<Integer> getIds(File file){
ArrayList<Integer> idList= new ArrayList<>();
String line = "";
int idNumber =0;
try{
BufferedReader reader4Id= new BufferedReader(new FileReader(file));
while((line=reader4Id.readLine())!=null){
idList.add(Integer.parseInt(line.substring(0,7)));
}
} catch (IOException e) {
e.printStackTrace();
}
return idList;
}
}