Java File Name Create generateFileName()

Here you can find the source of generateFileName()

Description

Generates and returns a new file name by appending the current date in front of the file name

License

Open Source License

Return

String

Declaration

public static String generateFileName() 

Method Source Code

//package com.java2s;
/* Copyright (c) Inmobia Mobile Technology, Inc. All Rights Reserved.
 * /* ww w .ja  va  2  s. c  o m*/
 * This software is the confidential and proprietary information of Inmobia 
 * Mobile Technology. ("Confidential Information").  You shall not disclose such 
 * Confidential Information and shall use it only in accordance with the terms 
 * of the license agreement you entered into with Inmobia Mobile Technology.
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    /**
     * formatter,used to format date
     */
    private static SimpleDateFormat formatter;

    /**
     * 
     * Generates and returns a new file name by appending the current date in
     * front of the file name
     * <p>
     * 
     * @return<code>String</code>
     */
    public static String generateFileName() {
        formatter = new SimpleDateFormat("yyyy-MM-dd");
        return formatter.format(Calendar.getInstance().getTime()) + "_Giant.xls";
    }
}

Related

  1. fileName(String path)
  2. fileName(String path)
  3. filename(String prefix, String sep, String index)
  4. FileName(String[] args)
  5. generateFileId(String userlogin)
  6. generateFileName()
  7. generateFileName(String fileName)
  8. generateFileNameWithoutExtension(final String testClassName, final String testId, final boolean includeDate)
  9. getRandomFileName(@Nullable final String prefix)