Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check file extension on Android

Tags:

android

In my application, when we browse the file from the SD card, the files will be .text, .jpg and mpeg4ie video files.

I want to store each file type into a particular folder. For example, .text files go to the text folder. When I select the file, how do I check the file extension?

like image 820
Nilesh Verma Avatar asked Feb 04 '11 05:02

Nilesh Verma


People also ask

How do you show file extensions on Android?

Tap the three vertical dots at the top right. Click on the “View Settings” option in the menu. Navigate to the “Advanced” tab. Check (to show) or uncheck (to hide) the “Show file extensions” option.

How do I find the file type on my phone?

Start by navigating to the location of the document, video, or image, and then perform a Haptic Touch gesture (long-press) on the item. On the menu that pops up, tap Info. You can then see the file format listed next to the file name.

How can I change file extension in mobile?

Long press on the file to select it. Then tap on the 'I' icon at the top right corner of ES File Explorer. Now you will get the 'Rename' pop-up dialogue on your Android mobile phone as shown in below screenshot. Here you can not only rename file but also change file extension.


1 Answers

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);     } } 

Which outputs:

jpg 
like image 138
Mike Lentini Avatar answered Oct 02 '22 20:10

Mike Lentini