I’m trying to make a method that write a txt plain file on the external memory..
And it works! .. but i want to insert the Date of creation on the footer of the file thorugh the file.exists() method.
If exists doesn’t insert date and if not exists insert the date..
My code is this..
File idea=new File(dir,titulo+".txt");
FileWriter writer=new FileWriter(idea);
if (!(idea.exists())){
texto.append("\n\n\tCreada :"+new Fecha().toString());
}
Supposing that dir is my path..
File dir =new File(Environment.getExternalStorageDirectory(),"/CMI");
and titulo is a parameter that the metod get when is called .. and contains the filename.
(Fecha it’s my Date class that returns a Date as String)
Try the above code. If you say
FileWriter writer = new FileWriter(idea);it creates a new file if it doesn’t exist. So theexist()method doesn’t make any difference and always returns true.