Home Java Java-get-example Java Get File Name



Java Get File Name
Posted on: October 24, 2008 at 12:00 AM
In order to get the file name, we have provided the path of file 'Hello.txt" to the constructor of class File.

Java Get File Name

     

In this section, you will study how to obtain the name of file. 

In order to get the file name, we have provided the path of file 'Hello.txt" to the constructor of class File. The method getName() returns the name of the file directory denoted by the pathname.

Here is the code of GetFileName.java

import java.io.File;  
  
  public class GetFileName  {  
  public static void main(String[] args){  
  File file = new File("C:\\Hello.txt");  
  String fileName= file.getName();
  System.out.println("The File is "+fileName);  
 }  
 }  

Output will be displayed as:

 

Download Source Code

 

Related Tags for Java Get File Name:
cfileideclassconstructorpathdirectorystructmethodgetconstordervinamereturnidtxttoeilnotinnoasmtrcldirmeprotorsurnrectctordirectatirhellohallnoteconsstrxtssrdthavsthelloctoprono


More Tutorials from this section

Ask Questions?    Discuss: Java Get File Name   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

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.