How do I use deleteFile () with an argument that contains a path separator?

The application implements a method deleteFile(String path)

that should delete the file located at the specified path.

If the path contains a path separator (character /

), the method throws an exception, but the full path must be used and must contain a separator character to delete a specific file. Due to conflicting conditions, I have not found a way to successfully delete the file.

Does anyone know how to get around the problem?

+2


source to share


2 answers


Not knowing which exception is hard to say. In general, it's best to avoid hardcoding path delimiters and use character instead File.separator

.

How are you going to delete the file? The File class has a delete method; is this what you are using?



I am guessing that the problem may not actually be related to the things I mentioned and should be resolved instead. Are you trying to access files or directories that your program does not have permission to access?

+1


source


According to the path javadoc, Application.deleteFile cannot contain path separator which is :

on Unix and ;

Windows, so at least according to the java doc you can delete a file with full path. Edit: '\' is File.separtor, not pathSeparator.



-1


source







All Articles