การคืนค่า Directory ปัจจุบันใน Java

การคืนค่า directory ปัจจุบันของ project java ที่เราทำงานอยู่ สามารถทำได้โดยใช้ system property ครับ ตัวอย่างของ system property อื่นๆสามารถศึกษาได้จากที่นี่ครับ .
1
String workingDir = System.getProperty("user.dir");
ตัวอย่าง
1
2
3
4
5
6
7
8
9
10
11
12
package demo.directory;
 
public class CurrentWorkingDirectoryExample {
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        String workingDir = System.getProperty("user.dir");
        System.out.println("Current working directory : " + workingDir);
    }
}
ผลลัพธ์ที่ได้คือ
1
Current working directory : D:\workspace\testjava

About Nop

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment