Java File.toString() method example

 Posted On  | Pooja Lakkihal 

In this java tutorial, You will learn how to convert the specified pathname into string. Java File.toString() method returns the pathname string of this abstract pathname.

Returns the pathname string of this abstract pathname. This is just the string returned by the getPath() method.

syntax

public String toString()

Returns

The string form of this abstract pathname.

Java File toString() example

  • Create file instance new File("c:\\technicalkeeda\\test.txt");
  • file.toString(); It will convert the specified pathname into string.
package com.technicalkeeda;

import java.io.File;

public class App {

    public static void main(String[] args) {

        File file = new File("c:\\technicalkeeda\\test.txt");

        System.out.println("Pathname to string  :- " + file.toString());

    }
}

output

Pathname to string  :- c:\technicalkeeda\test.txt


© technicalkeeda.com 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0239 seconds.