|
Java > IO > Get File Path Info |
|
Get File Path Info
The following example shows how to get the file path related info and file size.
|
package com.bethecoder.tutorials.io;
import java.io.File;
import java.io.IOException;
public class GetPathInfo {
/**
* @param args
*/
public static void main(String[] args) throws IOException {
File file = new File("C:\\NEW\\NEW_SUB\\file_ops.txt");
System.out.println(file);
System.out.println(file.getAbsolutePath());
System.out.println(file.getCanonicalPath());
System.out.println(file.toURL());
System.out.println(file.toURI());
System.out.println("File Size : " + file.length() + " bytes");
}
}
|
| |
It gives the following output,
C:\NEW\NEW_SUB\file_ops.txt
C:\NEW\NEW_SUB\file_ops.txt
C:\NEW\NEW_SUB\file_ops.txt
file:/C:/NEW/NEW_SUB/file_ops.txt
file:/C:/NEW/NEW_SUB/file_ops.txt
File Size : 12 bytes
|
|