I have this web browser app where I store the browsing history in a .txt file in the user's SD Card. The way I clear the history is just deleting the file, and I throw an exception if the History is cleared again if the file doesn't exist (This exception is temporary, as I plan to delete it in the future, but is in there for testing purposes). Is there a way to clear the history.txt without deleting the file that is cleaner? Here's the code snippet of how I go about "clearing" the file:
if(MainActivity.file.exists()){
MainActivity.file.delete();
for(int x = 0; x < 1000; x++){
urls[x] = "";
}
adap.notifyDataSetChanged();}
else if(!MainActivity.file.exists()){
throw new InvalidFileDeletionException("File does not exist and therefore can not be deleted.");
}