Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中设置文件名日期_Android_File - Fatal编程技术网

在android中设置文件名日期

在android中设置文件名日期,android,file,Android,File,我有一个备份数据库的应用程序,如下所示: // Method To Backup Database// public void OnClick_Backup(View v) { // Vibrates For 50 Mill// vibe.vibrate(50); int a = Calendar.DAY_OF_YEAR; int b = Calendar.DAY_OF_MONTH; File sd = new File(Environment.g

我有一个备份数据库的应用程序,如下所示:

// Method To Backup Database//
public void OnClick_Backup(View v) {

    // Vibrates For 50 Mill//
    vibe.vibrate(50);

    int a = Calendar.DAY_OF_YEAR;

    int b = Calendar.DAY_OF_MONTH;

    File sd = new File(Environment.getExternalStorageDirectory()+"/C.S. Tracker Backups");
    if(!sd.exists()){
        sd.mkdirs();
    }
        try {
            File sd2 = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();

            if (sd2.canWrite()) {
                String currentDBPath = "//data//jordanzimmittidevelopers.com.communityservicelogger//databases//community_service_Database";
                String backupDBPath = "/C.S. Tracker Backups/C.S. Backup";
                File currentDB = new File(data, currentDBPath);
                File backupDB = new File(sd2, backupDBPath);

                if (currentDB.exists()) {
                    FileChannel src = new FileInputStream(currentDB).getChannel();
                    FileChannel dst = new FileOutputStream(backupDB).getChannel();
                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();
                    Toast.makeText(getApplicationContext(), "Backup is successful to SD card", Toast.LENGTH_SHORT).show();
                }
            }
        } catch (Exception ignored) {
        }
    }
下面的代码告诉您应该将数据库文件定位到哪个路径:

   String backupDBPath = "/C.S. Tracker Backups/C.S. Backup";

如何使C.S.备份更改为备份的日期。例如,假设他们单击“立即备份”。我要写4-21-15。Thaks

您可以使用SimpleDataFormat类来获得所需的结果

SimpleDateFormat mFormatter = new SimpleDateFormat("MM-dd-yy");

Calendar c = Calendar.getInstance();
String backupDBPath =  mFormatter.format(c.getTime());