在Java中,新创建的文件的默认位置是什么? [英] In Java, what is the default location for newly created files?

查看:165
本文介绍了在Java中,新创建的文件的默认位置是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,新创建文件的默认位置是什么?

解决方案

如果应用程序的当前目录。如果例如您可以使用

  new FileOutputStream(myfile)
pre>

然后它在当前目录中创建,可以通过调用

  System.getProperty( user.dir来);但是,如果通过调用本机方法(非常不可能!)更改当前目录,则该属性不是更新。它可以被看作是应用程序的当前目录。



如果你在一个批处理文件中启动你的Java应用程序,并双击它的链接,当前目录将成为批处理文件所在的目录,但可以在链接中进行更改。



如果从命令行启动Java应用程序,则您已经知道该目录如果从IDE启动Java应用程序,则当前目录通常是项目根目录,但通常可以在启动配置中进行配置。

/ b>

更新2017-08:

您也可以随时找到当前的正确位置与新文件(。)。getAbsolutePath()


In Java, what is the default location for newly created files?

解决方案

If the current directory of the application. If e.g. you create a File by using

new FileOutputStream("myfile")

then it is created in the "current" directory, which can be retrieved by calling

System.getProperty("user.dir");

However if you change the current directory by calling native methods (very unlikely!), the property is not updated. It can be seen as the initial current directory of the application.

If you start your Java app in a batch file, and doubleclick on the link to it, the current directory will be the directory where the batch file resided, but this can be changed in the link.

If you start your Java app from the command line, you already know the directory you are in.

If you start your Java app from the IDE, the current directory is usually the project root, but this can usually be configured in the launch configuration.

UPDATE 2017-08:

You could also always find the current correct location with new File(".").getAbsolutePath().

这篇关于在Java中,新创建的文件的默认位置是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆