Home Discussion Discuss: Java Example program to get the current working directory

  • 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



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
General

Get current working directory in Java
Get current working directory in Java In this section we will discuss about how to get the the current working directory in java. Current working directory means the current working directory where java program execute. In java 

General

Java Example program to get the current working directory
Java Example program to get the current working directory       This example java program illustrates to get the current working directory (CWD). With the File class 

Java-Tutorials

Getting the Current Working Directory in Java
C:\nisha>javac GetCurrentDir.java C:\nisha>java GetCurrentDir Current Working Directory : C:\nisha C:\nisha> Download this example 

Java Tips and Examples

Find Current Temp Directory
; as key to get the current temp directory into getProperty() method...;    In this example we are find the current Temp... the current temp directory. The getProperty(String key) is defined into System class 

Java Beginners

Getting Current Directory from java - Java Beginners
in linux where i need to get the current directory of my java file... I'm using.../Softwares/apache-tomcat-5.5.27/logs How to get the directory of my current...://www.roseindia.net/java/java-get-example/get-CWD.shtml http://www.roseindia.net/java 

Java-Tutorials

Getting the Parents of file name path in Java
will learn how to get the parent directory of the current working directory. Program... name of the current directory.  getParent(): Above code returns the parent...;): This method returns the user's current directory. The getProperty() method 

General

Java program to get current date
Java program to get current date now       In this example program we have to get... run the program you will get the following output: Output: C 

General

Get Current Directory
Get Current Directory     ... in understanding Get Current Directory. For this we have a class name CurrentDir... the current directory and parent directory using following methods 

General

Get current Date and Time
Get current Date and Time In this section we will discuss about how to get current date and time in java. Java provide two classes, Date and calendar which will display the current date and time in java. SimpleDateFormat is used  

JSP-Tutorials

JSP Current Path
;       JSP Current Path is used to get the current... from 'JSP Current Path'. In this section, you will learn how to get the current...;request.getRealPath ("/") > is used to get the current path of the jsp 

General

Java Get Example
java.net.InetAddress class.    Java Example program to get the current working directory This example java program illustrates to get the current working directory (CWD). With the File class object we can get 

PHP Tutorial

PHP Get Base Directory
PHP Get Base Directory  To know the base directory we may use $_SERVER['DOCUMENT_ROOT']; Code: <?php //to know your base directory print ($_SERVER['DOCUMENT_ROOT']); ?>   Output: C:/wamp/www 

General

Java Get Example
to get the current working directory This example java program illustrates to get the current working directory (CWD). With the File class object we can... In this example java program we have to get the data type of the database table fields 

General

Java example program to get the operating system name of the system
Java example program to get the operating system name of the system       java get Operating... are working. So in java we have "os.name" property which provides us 

Java Beginners

How to get the current date in Java?
How to get the current date in Java?  Hi, I am new to Java and trying to write a program to get the current date. How to get the current date in Java? Thanks   Hi, Check the tutorial: Java program to get current date 

General

Get Current Thread
Get Current Thread      ... to describe you a code that helps you in understanding Get Current Thread. For this we have a class" Get Current Thread" implements Runnable interface.  1 

Programming Tutorials

Open Source Directory
Open Source Directory Open Source Java Directory The Open Source Java... scalability to current open source lightweight directory access protocol offerings... - to many different platforms.    Open Source Java Directory 

Programming Tutorials

Working With File,Java Input,Java Input Output,Java Inputstream,Java io Tutorial,Java io package,Java io example
to the current directory C:\nisha> If you try to run this program... to the existence of a corresponding file/directory. If the file exist, a program can... Working With File       

Java Tips and Examples

Find User Home Directory
;  In this example we are find user home directory. We are using System class  to get the information about system. System..." as key to get the user define home directory 

Java-Tutorials

JDBC: Get current TimeStamp Example
JDBC: Get current TimeStamp Example In this tutorial, we are going to describe how to get current TIMESTAMP using JDBC API. Get current TimeStamp : CURRENT...; In this example we are using TimeStamp to display the current timestamp. we 

Spring Framework Questions

JDBCTemplate BatchUpdate() example not working
JDBCTemplate BatchUpdate() example not working  Hi, I tried the JDBCTemplate BatchUpdate example, with IBM DB2 database. I updated the dataSource bean values accordingly. When I try, the program runs fine, however the database 

Java-Tutorials

JDBC: Get current Date and Time Example
JDBC: Get current Date and Time Example In this section, you will learn how... will get output - 17:04:30 Example :  In this example we are selecting current...) { System.out.println("Get Current Date and Time Example..."); Connection con = null 

Java Technology Tutorials

Java file get parent directory
Java file get parent directory In this section, you will learn how to get the parent directory of the file. Description of code: The package java.io.... and directories. You can see in the given example we have created a File object 

Java Beginners

how to copy the directory in to ftp server using java
the directory in to ftp server using java ?   Hello venaktehs As much as I know,You can do this as follows: First,Create a directory in the current working directory with the same name (which you wish to copy) as: issueCommand 

Java Beginners

how to get current date without system date
how to get current date without system date  is there any possiblity to get current date instead of system date in Java, as i dont want to change date in program and if i change date in OS automatically change in program also 

General

Java get class directory
Java get class directory     ... to fetch the class directory's path by the class name. To get the class directory's... called the getClass() method and to get the path of that class directory we 

Servlets

Working with Tomcat Server
the application in Java technology you can get any host and then deploy it on the internet. Earlier it was a difficult task to get a good host for hosting. So, let's... Working with Tomcat Server    

Java-Tutorials

Getting the current date
date of the system. In this section, through the given program you can get the current date in the proper format (Day/Month/Year). This program shows... Getting the current date      

Programming Tutorials

Working with CSS(CSS Manipulation)
matched element. Example : Following code get the current horizontal position...; the first matched element. Example : Following code get the current...( ) This method get the height of the first matched element. Example : $(" 

Java-Tutorials

Getting the Current Time
Getting the Current Time       This section shows the way of getting  the current time of the system. In this section, through the given program you can get the current 

DMCA.com