Constructing a File Name path
In Java, it is possible to set dynamic path, which is helpful for mapping local file name with the actual path of the file using the constructing filename path technique.
As you have seen, how a file is created to
the current directory where the program is run. Now we will see how the
same program constructs a File
object from a more complicated
file name, using the static constant File.separator or File.separatorCharto
specify the file name in a platform-independent way. If we are using Windows platform then the value of this
separator is ' \ ' .
Lets see an example to create a file to the specified location.
|
Output of the program:
C:\nisha>javac PathFile.java C:\nisha>java PathFile New file "myfile.txt" has been created to the specified location The absolute path of the file is: C:\nisha\example\myfile.txt C:\nisha> |
Another program set the dynamic path using File.separator given below:
import java.io.*;
|
Output of the program:
C:\java>java ConstructingFileNamePath The path of the file is : \tapan\joshi |