public static void Replace_Record(String editTerm, String newItem, String newAmount, String newPrice){
String filepath="temp_Food_Item.txt";
String tempfile= "temp_Food_Item_temp.txt";
File oldFile= new File(filepath);
File newFile=new File(tempfile);
String item=""; String quantity=""; String price="";
System.out.println("working ");
try{
//System.out.println("working pt1");
FileWriter fw= new FileWriter(tempfile,true);
BufferedWriter bw= new BufferedWriter(fw);
PrintWriter pw= new PrintWriter(bw);
x = new Scanner(new File(filepath));
x.useDelimiter("[,/n]");
//System.out.println("working pt2");
while(x.hasNext()){
//System.out.println("working pt3");
item=x.next();
quantity=x.next();
price=x.next();
if(item.equalsIgnoreCase(editTerm)){
pw.println(newItem+","+newAmount+","+newPrice);
}
else{
//System.out.println("working pt4 ");
pw.println(item+","+quantity+","+price);
}
}
x.close();
pw.flush();
pw.close();
oldFile.delete();
File dump=new File(filepath);
newFile.renameTo(dump);
}
catch(Exception e){
System.out.println("Error declared");
}
}
Я не понимаю, где я ошибся, но печатается «объявлена ошибка», поэтому я отладил и обнаружил, что после работы pt1 он останавливается и уходит, чтобы поймать, пожалуйста, помогите? Дополнительная информация включает в себя: я создаю базу данных для ресторана и вводю информацию в текстовые файлы в последовательности item_name, item_amount, item_price , поэтому я беру свои новые значения из main и передаю их методу теоретически, он сначала дублирует файл, пока не доходит до строк, которые я хочу удалить, а затем заменяет их и возвращается к копированию строк из реальных файлов. но каждый раз, когда я запускаю это, я получаю улов.
TIA