2:14 am - Wednesday April 26, 2017

Get Filepath program to get the pathname of the file using getPath() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

 

Get Filepath program to get the pathname of the file using getPath() method

EXAMPLE PROGRAM




import java.io.File;

public class StrFilepath {
	public static void main(String[] args) {

		File f = null;
		String v;
		boolean bool = false;

		try {
			// create new file
			f = new File("test.txt");

			// pathname string from abstract pathname
			v = f.getPath();

			// true if the file path exists
			bool = f.exists();

			// if file exists
			if (bool) {
				// prints
				System.out.print("pathname: " + v);
			}
		} catch (Exception e) {
			// if any error occurs
			e.printStackTrace();
		}
	}
}



Output

 

pathname: test.txt

 

Description

 

The java.io.File.getPath() method converts the abstract pathname into pathname string. To separate the names in the name sequence the resulting string uses the default name-separator character.

 

Declaration

Following is the declaration for java.io.File.getPath() method:

public String getPath()

Parameters

 

 

  • Not Applicable.

 

 

Return Value

 

The method returns pathname string form of this abstract pathname.

 

Exception

 

 

  • Not Applicable.

 

BACK

Filed in: Z-A All Java Codes

Comments are closed.