Home Tutorialhelp Allcomments Java Java Get Example Get File Extension

 
 

Comments

 
User Comments for the tutorial:

Java example program to get extension



Comments

too long
String extension = filename.substring(filename.lastIndexOf(".")+1); 

Fails on some inputs
eg ".htaccess" or "noextension" Here's a fixed version: // default in case there's no extension: String baseName = fileName; String extension = ""; // split on position of dot in name int lastDotPos = fileName.lastIndexOf(".");  

Related Tutorial and Articles
General

Java example program to get extension
Java example program to get extension       java get extension To get the file name and file extension separately we can do the string manipulation on the file name. Suppose 

Java Technology Tutorials

Java filename without extension
Java filename without extension In his section, you will learn how to get the file name without extension. Description of code: In one of the previous... file without extension. You can see in the given example, we have created 

General

Java get Filename without Extension
Java get Filename without Extension   ... the filename without extension. For this, the file name or the directory name is being provided. file.getName()- This method returns the file name 

Java Tips and Examples

Java Display File-Extension
Java Display File-Extension   ... the file extension of the file. Here you will be asked to enter the file name and then you will get the extension of the file. Description of the code 

Java Tips and Examples

Java Change File-Extension
Java Change File-Extension     ... is to be changed and then you will get the file name with the changed extension... Enter file extension to change the file type: java FileExtension has 

General

Java Get Example
Java Get Example      .... Java Get Examples.. Get host name in Java: This example is going... practice   IP Address:  This Java Get IP Address example 

General

Java Get Example
Java Get Example      .... Java Get Examples.. Get host name in Java: This example... is method and how to use the get method in Java, this example is going 

Java Technology Tutorials

Java file get size
Java file get size In this section, you will learn how to get the size of a file. Description of code: You can see in the given example, we have created... args[]) { File file = new File("C:/java.txt"); long filesize = file.length 

Java Tips and Examples

Example - Display Extension
Java: Example - Display Extension This program reads in a file name... 26 // Purpose: Display the extension (with .) of a file name. // File...; // The file name the user entered. String extension; // The extension 

General

Java: Example - Change Extension
Java: Example - Change Extension Problem: Change the extension of a file name //============================================== changeExtension // changes extension to new extension // example: x = changeExtension 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.