Question: I am developing an app that loops for several hours or even maybe days and what I want is that it loops past the current day into the next it creates a new file with a new file name.
Can anyone help me with the logic ?
Here is my code:

```
    timedata= new File(timedata)
    String timedatafile=  "/sdcard/timedata"+"-"+formattedDate+".csv";

    if(MsureData.exists()!=true)
{
    timedata.createNewFile();
    Calendar c = Calendar.getInstance();
    String formattedDate = df.format(c.getTime()); 
    // do stuff
}

```

Answer: 
You still aren't providing enough context. The code you posted doesn't even compile.

* `formatedDate` is defined after being used
* You use `timedata` as both the argument to the `File` constructor and the resulting new instance. There is no `File` constructor that takes a single `File` instance ([Source](http://docs.oracle.com/javase/8/docs/api/java/io/File.html#constructor.summary)).

However, based on what you have, I would guess that:

You are not making a new `File` instance once you determine a new one must be created. You create the `timedata` instance and calling `createNewFile()` before you are getting the new date. Once you have determined the date you want to use, only then can you create the `File` instance and create the file. Just updating the value in `formattedDate` will not change the file name of the already existing `File` instance.
```
Date currentDate = new Date(System.currentTimeMillis());

```

From this you can get current date of system.