如何在代码运行的相同位置创建一个目录?

huangapple 未分类评论61阅读模式
标题翻译

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.

huangapple
  • 本文由 发表于 2020年3月16日 16:24:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/60702509.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定