标题翻译
How to create a directory at the same place as the code runs?
问题
我正在尝试将一些输出文件保存在与我的Java类相同的位置。我想使用相对路径,这样当我将代码移动到其他地方时就不会有任何问题。
目前它将我的文件写入/home/myUser/output_j.erome
,实际代码如下:
FileWriter out = new FileWriter("output_j.erome", true);
我找不到如何在与我的Java类相同的位置动态创建文件夹,然后将我的文件添加到其中。
英文翻译
I'm trying to save some output files at the same place as my Java classes. I want to use a relative path so there isn't any problem when I move the code somewhere else.
For the moment it writes my file under /home/myUser/output_j.erome
and the actual code is :
FileWriter out = new FileWriter("output_j.erome",true);
I can't find how to create dynamically the folder at the same place as my Java classes and then add my file in it.
专注分享java语言的经验与见解,让所有开发者获益!
评论