Java Long Number to Time getUploadPath(String fileName, long time)

Here you can find the source of getUploadPath(String fileName, long time)

Description

get Upload Path

License

Apache License

Declaration

public static String getUploadPath(String fileName, long time) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

    public static String getUploadPath(String fileName, long time) {
        SimpleDateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
        String uploadPath = "/upload/" + formater.format(new Date()) + "/"
                + time + getFileExt(fileName);
        File dir = new File(getWebRoot() + uploadPath);
        if (!dir.exists()) {
            try {
                dir.mkdirs();/*from  ww w  . j  ava  2s. co  m*/
            } catch (Exception e) {
                e.printStackTrace();
                return "";
            }
        }
        return uploadPath;
    }

    public static String getFileExt(String fileName) {
        return fileName.substring(fileName.lastIndexOf("."));
    }

    public static String getWebRoot() {
        File f = new File("");
        return f.getAbsoluteFile().getAbsoluteFile().getPath();
    }
}

Related

  1. getTimeStr(long timeLong)
  2. getTimeString(long nanoTime)
  3. getTimeString(long time)
  4. getTimeTagged(long time, boolean round)
  5. getTimeText(Long oldTime)
  6. logDuration(Logger logger, Level level, long startTime, String message)
  7. long2Str(long time)
  8. longToPgnDate(long time)
  9. longToTimedDate(long time)