Given a string location and string file name, is it possible to execute a java command to delete said file? If so, what package or class should I look at using for this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using the file’s string location and name, get a file handle for it:
Note that you should encapsulate this with appropriate code to catch potential problem cases, such as if Java does not have the permission to delete that file on your current system. Or, if the file isn’t found or another, similar, edge case.
The API you want to look at in this case is
java.io.File. Note that while this function returns aboolindicating whether the action succeeded, it might also throw aSecurityExceptionif the user does not have permission to take the action.