String book_name = book_list.getModel().getElementAt(book_list.getSelectedIndex()).toString();
System.out.println("File name : "+book_name);
File f = new File("C:\\Users\\Surya\\Documents\\NetBeansProjects\\New_Doodle\\Library\\"+book_name);
System.out.println("Path:"+f.getAbsolutePath());
if(f.exists())
System.out.println("Book Exists");
else
System.out.println("Not Exixts");
if(f.isFile())
{
System.out.println("It is File");
}
else
System.out.println("It is Directory");
System.out.println(f.isAbsolute());
if (f.delete())
{
JOptionPane.showMessageDialog(null, "Book Deleted");
}
else
{
JOptionPane.showMessageDialog(null, "Operation Failed");
}
输出
File name : `Twilight03-Eclipse.pdf`
Path: `C:\Users\Surya\Documents\NetBeansProjects\New_Doodle\Library\Twilight03-Eclipse.pdf`
Book Exists
It is File
true
Operation Failed (dialog box)
File is not deleted