Android examples for java.io:File Name
relocate Temp Photo For Expense
//package com.java2s; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import android.os.Environment; import android.util.Log; public class Main { public static final String TEMP_PIC_PATH = "asdf/PhotoTemp"; public static final String EXPENSE_PIC_PATH = "asdf/ExpensePhoto"; public static String relocateTempPhotoForExpense() { // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss") .format(new Date()); File fromDir = new File(Environment.getExternalStorageDirectory(), TEMP_PIC_PATH);//from www . ja va 2 s . c o m File toDir = new File(Environment.getExternalStorageDirectory(), EXPENSE_PIC_PATH); File from = null; File to = null; if (fromDir.exists()) { from = new File(fromDir.getPath() + File.separator + "IMG_TEMP.jpg"); } else { return null; } if (!toDir.exists()) { if (!toDir.mkdirs()) { Log.d("DriverConnex", "Failed to create directory!"); return null; } } to = new File(toDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); from.renameTo(to); return "IMG_" + timeStamp + ".jpg"; } }