如何检查android的文件扩展名 [英] How to check file extension in android

查看:124
本文介绍了如何检查android的文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,当我们浏览文件从SD卡的文件将被.text区段,jpg和mpeg4ie视频文件。我想保存每个文件类型到一个特定的文件夹。例如,文件的.text到文本文件夹。我的问题是,当我选择文件,我怎么检查的文件扩展名?

In my application, when we browse the file from sdcard the file will be .text, .jpg and mpeg4ie video file. I want to store each file type into a particular folder. For example, .text files go to the text folder. My question is when I select the file, how do I check the file extension?

推荐答案

我会得到的文件名作为字符串,将其分割成一个数组。作为分隔符,然后拿到阵列,这将是文件扩展名的最后一个索引。例如:

I would get the file name as a String, split it into an array with "." as the delimiter, and then get the last index of the array, which would be the file extension. For example:

public class main {
    public static void main(String[] args) {
        String filename = "image.jpg";
        String filenameArray[] = filename.split("\\.");
        String extension = filenameArray[filenameArray.length-1];
        System.out.println(extension);
    }
}

它输出:

jpg

这篇关于如何检查android的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆