private void jLabel23MouseClicked(java.awt.event.MouseEvent evt) {
Scanner sc;
try {
sc = new Scanner (new FileReader("src\\main\\Profiles.txt"));
String name, newPrice,fname,lname,male,female,a,cin,add,group;
String line ="",content="";
name = userNameField6.getText();
while(sc.hasNextLine())
{
line = sc.nextLine();
Scanner lineinput = new Scanner(line);
lineinput.useDelimiter("/");
String gr = lineinput.next();
String firstname = lineinput.next();
String lastname = lineinput.next();
String age = lineinput.next();
String gender = lineinput.next();
String contact = lineinput.next();
String address = lineinput.next();
if(name.equals(firstname))
{
line = "";
}
content = content +line;
}
JOptionPane.showMessageDialog(null, "Profile Has Been Deleted");
sc.close();
FileWriter writer,writer2;
try {
writer = new FileWriter("src\\main\\Profiles.txt");
writer2 = new FileWriter("src\\main\\Profiles_1.txt");
writer.write(content);
writer.close();
writer2.write(content);
writer2.close();
} catch (IOException ex) {
}
} catch (FileNotFoundException ex) {
}
}
它会告诉我这个错误
enter image description here
这段代码早先起作用,然后突然停止了工作。基本上,它所做的只是将一行文本文件更改为空白文件。我是编程新手,不知道该怎么做。