Marya
Marya

Reputation: 332

Putting date as xml file name

I want to create an xml file and put the date as name

//I create here a new xmlfile called Date.xml

Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss");
String Date= df.format(c.getTime());
File newxmlfile = new File(Environment.getExternalStorageDirectory()+ "/"+Date+".xml");

try {
Log.v("CreateXML", "create file:" + newxmlfile.createNewFile());
} catch (IOException e) {
Log.e("IOException", "exception in createNewFile() method");
}
FileOutputStream fileos = null;
try {
fileos = new FileOutputStream(newxmlfile);
} 
catch (FileNotFoundException e) {
 Log.e("FileNotFoundException", "can't create FileOutputStream");
    }

The Xml file is not created and i get that error

E/(12438): 19-mars-2014 05:06:19 E/IOException(12438): exception in createNewFile() method E/FileNotFoundException(12438): can't create FileOutputStream E/Exception(12438): error occurred while creating xml file

Upvotes: 0

Views: 405

Answers (1)

D.R.
D.R.

Reputation: 21194

Just use Date instead of the current filename "new".

E.g.: new File(Environment.getExternalStorageDirectory()+ "/"+Date+".xml");

Upvotes: 2

Related Questions