/** * Show how to manipulate directory and file path in portable way. * @author Xuan Ngo */ import java.io.File; import java.io.IOException; public class DirFileHandling { public static void main(String[] args) { // Get current directory path File oFile = new File("."); String sCurrDirPath = ""; try { sCurrDirPath = oFile.getCanonicalPath(); System.out.println(sCurrDirPath); } catch(IOException ex) { System.out.println(ex.getMessage()); } // Create the path of a new sub-directory. String sNewDirPath = sCurrDirPath + File.separator + "NewDirName"; System.out.println(sNewDirPath); // Create the path of a file under the sub-directory. String sNewFilePath = sCurrDirPath + File.separator + "NewDirName"+ File.separator + "NewFileName.txt"; System.out.println(sNewFilePath); } }