漂在爪洼島上
Java is my life,but not all!
posts - 3, comments - 6, trackbacks - 0, articles - 9
BlogJava
::
首頁
::
新隨筆
::
聯系
::
聚合
::
管理
日歷
<
2025年7月
>
日
一
二
三
四
五
六
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
給我留言
查看公開留言
查看私人留言
隨筆分類
simple life(3)
隨筆檔案
2009年6月 (2)
文章分類
Database(1)
J2EE(4)
J2SE(2)
xml(4)
工具介紹(1)
文章檔案
2009年11月 (1)
2009年6月 (8)
新聞檔案
2009年6月 (1)
我的連接
51的博客
一個曾經留戀過的地方
csdn的博客
曾經在CSDN的技術地址
新浪相冊
08年之后的相片那里幾乎都會找到。。。
搜索
最新評論
1.?re: google關閉中國區搜索功能
@can212
仁兄,請看看文章發布的時間
那個時間google因為she huang ,還上過CCTV,當時大中華區就關閉了提示功能,不清楚背景請勿亂說
--周競先
2.?re: google關閉中國區搜索功能
根本就沒關閉
--can212
3.?re: google關閉中國區搜索功能
他們在懼怕什么?
他們在為什么東西的霸道轉移輿論?
--馬達+斯加
4.?re: google關閉中國區搜索功能
評論內容較長,點擊標題查看
--天堂露珠
5.?re: google關閉中國區搜索功能
只能證明ZF是SB
--...
閱讀排行榜
1.?google關閉中國區搜索功能(1298)
2.?2009年6月18號下午在blogjava開博了(203)
評論排行榜
1.?google關閉中國區搜索功能(6)
2.?2009年6月18號下午在blogjava開博了(0)
在java application中獲取當前工程/文件地址
Posted on 2009-06-30 10:27
周競先
閱讀(1397)
評論(0)
編輯
收藏
所屬分類:
J2SE
1
String projectURL
=
System.getProperty(
"
user.dir
"
) ;
2
System.out.println(
"
工程所在的路徑地址:
"
+
projectURL);
3
輸出結果:
1
工程所在的路徑地址:D:\J2EE\MyEclipse6.0_workspace\mobilenet2.
0
簡單說明:
這個JAVA APPLICATION文件是在mobilenet2.0的工程里面,故打印出來的是工程所在路徑地址
剛去csdn的博客看了一下,發現原來已經總結過一次,現在轉過來
1
2
3
1
、利用 System.getProperty() 函數獲取當前路徑:
4
5
System.out.println(System.getProperty(
"
user.dir
"
));
//
user.dir 指定了當前的路徑
6
7
8
9
2
、使用 File 提供的函數獲取當前路徑:
10
11
File directory
=
new
File(
""
);
//
設定為當前文件夾
12
13
try
{
14
15
System.out.println(directory.getCanonicalPath());
//
獲取標準的路徑
16
17
System.out.println(directory.getAbsolutePath());
//
獲取絕對路徑
18
19
}
catch
(Exceptin e)
{}
20
21
22
23
File.getCanonicalPath() 和 File.getAbsolutePath() 大約只是對于
new
File(
"
.
"
) 和
new
File(
"
..
"
) 兩種路徑有所區別。
24
25
26
27
# 對于 getCanonicalPath() 函數,“ .
"
就表示當前的文件夾,而” .. “則表示當前文件夾的上一級文件夾
28
29
# 對于 getAbsolutePath() 函數,則不管” . ”、“ .. ”,返回當前的路徑加上你在
new
File() 時設定的路徑
30
31
# 至于 getPath() 函數,得到的只是你在
new
File() 時設定的路徑
32
33
34
35
比如當前的路徑為 C:\test :
36
37
File directory
=
new
File(
"
abc
"
);
38
39
directory.getCanonicalPath();
//
得到的是 C:\test\abc
40
41
directory.getAbsolutePath();
//
得到的是 C:\test\abc
42
43
direcotry.getPath();
//
得到的是 abc
44
45
46
47
File directory
=
new
File(
"
.
"
);
48
49
directory.getCanonicalPath();
//
得到的是 C:\test
50
51
directory.getAbsolutePath();
//
得到的是 C:\test\.
52
53
direcotry.getPath();
//
得到的是 .
54
55
56
57
File directory
=
new
File(
"
..
"
);
58
59
directory.getCanonicalPath();
//
得到的是 C:\
60
61
directory.getAbsolutePath();
//
得到的是 C:\test\..
62
63
direcotry.getPath();
//
得到的是 ..
64
65
66
67
關于System.getProperty方法的參數見
68
69
70
71
Life,simple and happy!
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
在java application中獲取當前工程/文件地址
關于讀文件
Powered by:
BlogJava
Copyright © 周競先
主站蜘蛛池模板:
汽车
|
玉溪市
|
麦盖提县
|
敦化市
|
桃源县
|
肇州县
|
民乐县
|
西丰县
|
双牌县
|
惠来县
|
仪陇县
|
沙河市
|
苏尼特左旗
|
广安市
|
自治县
|
榕江县
|
武宣县
|
广水市
|
垦利县
|
庆安县
|
科技
|
囊谦县
|
花垣县
|
通榆县
|
堆龙德庆县
|
紫阳县
|
内黄县
|
汽车
|
乐昌市
|
乌鲁木齐市
|
景泰县
|
通河县
|
犍为县
|
城市
|
义马市
|
小金县
|
离岛区
|
东乡
|
余江县
|
岳阳县
|
茶陵县
|