The above code work in both Windows and Linux environments as a standalone app, as above.
However, when we use it in Tomcat's context, it works only in Windows (ex: shows as 'C:/tomcat/bin' as the current working directory), however it shows up as '/' in Linux when it actually should be showing up as a '/opt/apps/Tomcat/bin'
javaSAGI KARTEEKA VARMA June 26, 2012 at 2:42 PM
import java.io.File; class DirList { public static void main(String args[]) { String dirname = "/java"; File f1= new.File(dirname); if(f1.isDirectory()) { System.out.println("Directory of "+ dirname); String s[]=f1.list(); for(int i=0;i<s.length;i++) { File f =new File(dirname+"/"+s[i]); if(f.isDirectory()) { System.out.println(s[i]+"is a directory"); } else { System.out.println(s[i]+"is a File"); } } } else { System.out.println(dirname+"is not a directory"); } } }
current working directory in Java - tomcat contextananth October 12, 2012 at 11:15 AM
The above code work in both Windows and Linux environments as a standalone app, as above. However, when we use it in Tomcat's context, it works only in Windows (ex: shows as 'C:/tomcat/bin' as the current working directory), however it shows up as '/' in Linux when it actually should be showing up as a '/opt/apps/Tomcat/bin'
Post your Comment