Home Tutorial Java Core Files Java file get name

 
 

Share on Google+Share on Google+
Java file get name
Posted on: April 17, 2006 at 12:00 AM
Advertisement
In this section, you will learn how to get the name of the file.

Java file get name

In this section, you will learn how to get the name of the file.

Description of code:

You can see in the given example, we have created an object of File class and specified a file in the constructor. Then we have called the method getName() through the object of File class which returns the name of the file.

Here is the code:

import java.io.*;

public class FileGetName {
	public static void main(String[] args) {
		File file = new File("C:/Answers/File/out.txt");
		String st = file.getName();
		System.out.println("File name is: " + st);
	}
}

Through the method getName() of File class, you can get the name of any file.

Output:

File name is: out.txt
Advertisement

Related Tags for Java file get name:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 17, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com