Android Open Source - android-common-utility File Utils






From Project

Back to project page android-common-utility.

License

The source code is released under:

Apache License

If you think the Android project android-common-utility listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.xckevin.android.util;
/*from  ww w  .  j  av a  2 s.  co m*/
import java.io.File;
import java.util.UUID;

/**
 * file utilities
 *
 * @author Kevin
 */
public class FileUtils {

    /**
     * get file name from url
     *
     * @param url
     * @return
     */
    public static String getFileNameByUrl(String url) {
        if (StringUtil.isEmpty(url)) {
            return null;
        }
        int index = url.lastIndexOf('?');
        int index2 = url.lastIndexOf("/");
        if (index > 0 && index2 >= index) {
            return UUID.randomUUID().toString();
        }
        return url.substring(index2 + 1, index < 0 ? url.length() : index);
    }

    /**
     * get file extend name
     *
     * @param fileName
     * @return
     */
    public static String getFileExtendName(String fileName) {
        if (StringUtil.isEmpty(fileName)) {
            return null;
        }
        int index = fileName.lastIndexOf('.');
        if (index < 0) {
            return "unknown";
        } else {
            return fileName.substring(index + 1);
        }
    }

    public static boolean isFileExists(String filePath) {
        if (StringUtil.isEmpty(filePath)) {
            return false;
        }

        return new File(filePath).exists();
    }
}




Java Source Code List

com.xckevin.android.Env.java
com.xckevin.android.util.AppUtil.java
com.xckevin.android.util.FileUtils.java
com.xckevin.android.util.MD5.java
com.xckevin.android.util.StringUtil.java
com.xckevin.android.widget.AutoSwitchImageView.java
com.xckevin.android.widget.PullToLoadListView.java