Here you can find the source of getSimpleDataFormattedFile(File file)
Parameter | Description |
---|---|
file | target file |
public static File getSimpleDataFormattedFile(File file)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w . jav a 2s.c o m * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.*; import java.text.SimpleDateFormat; import java.util.*; public class Main { /** * This method will be called for create a backup file. * * @param file target file * @return File backup file whose filename consists of "hogehoge.yyyyMMddHHmmss.ext" or * "hogehoge.yyyyMMddHHmmss". */ public static File getSimpleDataFormattedFile(File file) { SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); //$NON-NLS-1$ String date = df.format(new Date()); String filename = file.getName(); int index = filename.lastIndexOf("."); //$NON-NLS-1$ if (index != -1) filename = filename.substring(0, index) + "." + date + "." + filename.substring(index + 1); //$NON-NLS-1$ //$NON-NLS-2$ else filename = filename + "." + date; //$NON-NLS-1$ File dest = new File(file.getParentFile(), filename); return dest; } }