Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Java Get File Name

In order to get the file name, we have provided the path of file 'Hello.txt" to the constructor of class File.

Ads

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

 

Advertisements

Share on Google+Share on Google+

Java Get File Name

Posted on: October 24, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Java Get File Name   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Wendy
June 7, 2012
Java Script

I want to pull just the file name "2564 QuailSpring" and the file date "06/06/2012" from my file folders. What is the simplest script to use in jGrasp?

Ads

 

Ads