File class object doesn’t delete files when running in a server java

I’ve been working on my final programming class project, and I am stuck right now, I have to create an inventary for a company. I use textpad to write the code and the icarnegie workbench, to put the classes on it and run it, so the thing is that i have this servlet and from there I call the class called Delete, this class has various methods, each of them deletes a file, something like this:

import java.io.*;
public class Delete{

String nombre;


public Delete(String n){
 nombre=n;
 }


public void deleteNombre(){

File objt = new File("C:/Inventario/"+nombre+"/nombre.txt");
objt.delete();

 }

public void deleteCodigo(){

File objt = new File("C:/Inventario/"+nombre+"/codigo.txt");
objt.delete();

 }

public void deletePrecio(){

File objt = new File("C:/Inventario/"+nombre+"/precio.txt");
objt.delete();

 }

public void deleteCantidad(){

File objt = new File("C:/Inventario/"+nombre+"/cantidad.txt");
objt.delete();

 }



 }

When I try to call this from the servlet, I can compile successfully, I don’t get any errors. when I put this code on a main class and run it, in terminal, the files are deleted, but when I use this method, calling it from a servlet, it just doesn’t happen. How can this happen and how can I fix it?

Answer

The files are most likely still open somewhere else in the code.

Leave a Reply

Your email address will not be published. Required fields are marked *