I'm having some problems with file deletion in Java. I'm doing a simple CRUD application for my OOP class and we need to use files as database. I tried to create a function to erase the database (Delete all database files and save new empty ones), but, so far, I always receive the success message, but the files still there, untouched.
I have the file path set this way in my config.java file:
private String fileBooks = "books.dat";
private String fileUsers = "users.dat";
private String fileOperations = "operations.dat";
I have this function, responsible for file erase:
public void deleteFiles() {
try {
File fbooks = new File(config.getFileBooks());
File fusers = new File(config.getFileUsers());
File fop = new File(config.getFileOperations());
if(fbooks.delete() && fusers.delete() && fop.delete()){
JOptionPane.showMessageDialog(null, "Success!",
"Database cleaning", JOptionPane.PLAIN_MESSAGE);
}else{
JOptionPane.showMessageDialog(null, "Error!",
"Database cleaning", JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
I checked the inheritance, the controller, everything looks fine. What I'm doing wrong? Is it a problem with the path?
If is useful information I'm running a Ubuntu 14.04 LTS, using NetBeans to code.
Any help and code advice will be welcome.
EDIT:
I added the System.out.println(fbooks.getAbsoluteFile())
this was my output:
/home/dotk/Dropbox/College/OOP/TP02/hw02/books.dat
/home/dotk/Dropbox/College/OOP/TP02/hw02/users.dat
/home/dotk/Dropbox/College/OOP/TP02/hw02/operations.dat
Do I need to change the path? I want the program to be OS independent, and it will be probably tested in a windows machine.
EDIT 2
I changed the file names, now they don't have the "./" but still not working. I verified that isn't any other open streams to the files, the only ones that run are in the start of the program to load the informations in ArrayLists, but they are closed after.