This Code can be used to delete a list of files and in turn the reponse will be a String containg Success or error for every single file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import java.io.File; import org.apache.log4j.Logger; public class Testing { private static final Logger logger = Logger.getLogger(Testing. class ); //This function will delete the file and will return the status. private static boolean deletefile(String file) { File f1 = new File(file); boolean success = f1.delete(); if (!success) { logger.debug( "Deletion failed." ); System.exit( 0 ); } else { logger.debug( "File deleted." ); } return success; } public static void main(String[] args) { boolean resultVal; StringBuffer result = new StringBuffer(); if (args[ 0 ].length() < 0 ) { logger.debug( "File has not been mentioned." ); } else { String[] results = args[ 0 ].split( "," ); for ( int i = 0 ; i < results.length; i++) { logger.debug(results[i]); //call the delete function resultVal = deletefile(results[i]); if (resultVal == true ) { result.append( "Sucess," ); } else { result.append( "Error," ); } } //Delete the last comma appended to the string result.deleteCharAt(result.length() - 1 ); logger.debug(result); } } } |