Topic: 怎样可得到当前目录?

  Print this page

1.怎样可得到当前目录? Copy to clipboard
Posted by: Butterfly_125
Posted on: 2005-07-20 20:46

问个很菜的问题:我想在当前目录下的q1文件夹下,建一个文件。File f = new File("\\q1\Hello.txt");这样写是错的。应该怎样写?

2.Re:怎样可得到当前目录? [Re: Butterfly_125] Copy to clipboard
Posted by: why
Posted on: 2005-07-20 20:55

Why don't you try to look for it first?
http://www.cjsdn.net/post/view?bid=1&id=150435

3.Re:怎样可得到当前目录? [Re: Butterfly_125] Copy to clipboard
Posted by: Butterfly_125
Posted on: 2005-07-20 21:03

看了,可还是不知道怎么写
File f = new File("\\q1\Hello.txt");
这句应该怎么改?

4.Re:怎样可得到当前目录? [Re: Butterfly_125] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-07-21 11:11


String sCurrDir = java.lang.System.getProperty("user.dir"); // the dir you are running the program
File f = new File(sCurrDir + "\\Hello.txt"); //double backslash to avoid escape

5.Re:怎样可得到当前目录? [Re: Butterfly_125] Copy to clipboard
Posted by: Butterfly_125
Posted on: 2005-07-21 13:10

Thank you very much ,my friend gongshi again!

6.Re:怎样可得到当前目录? [Re: Butterfly_125] Copy to clipboard
Posted by: xxqn
Posted on: 2005-07-23 20:14

这样的程序不能跨平台运行,目录分割符应该采用:System.getProperties().getProperty("line.separator")获取当前系统的分割符。

7.Re:怎样可得到当前目录? [Re: xxqn] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-07-23 22:28

xxqn wrote:
这样的程序不能跨平台运行,目录分割符应该采用:System.getProperties().getProperty("line.separator")获取当前系统的分割符。


Very good to point this out. However, it should be "file.separator".
Thanks!

8.Re:怎样可得到当前目录? [Re: Butterfly_125] Copy to clipboard
Posted by: Butterfly_125
Posted on: 2005-07-24 02:15

哦,谢谢了xxqn!!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923