eclipse 获取应用程序路径以创建新文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12562500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:02:44  来源:igfitidea点击:

Get Application Path to create a new File

javaeclipsepath

提问by Gapchoos

How can I get the Application path of a Project in a String variable LogPath. The LogPath is used later on to create a Log File of the Project. Am using Eclipse for coding.

如何在字符串变量 LogPath 中获取项目的应用程序路径。LogPath 稍后用于创建项目的日志文件。正在使用 Eclipse 进行编码。

采纳答案by Mukul Goel

USE

String AbsolutePath = new File(".").getAbsolutePath();

Explanation : File(".")represents the current directory and getAbsoultePath()returns absolute path to the current directory.

说明:File(".")表示当前目录,getAbsoultePath()返回当前目录的绝对路径。

Hope it helps :-)

希望能帮助到你 :-)

回答by Jiri Kremser

I would use

我会用

String logPath = new File(".").getAbsolutePath();

.. for start.

..开始。

回答by Keethanjan

Which Language are you using?

您使用的是哪种语言?

Java:

爪哇:

File directory = new File (".");
System.out.println ("Current directory's canonical path: " +     directory.getCanonicalPath());
System.out.println ("Current directory's absolute  path: " + directory.getAbsolutePath());

回答by AlexR

This call: new File(".").getAbsolutePath()gives you the current working directory of your application. I hope this answers your question.

此调用:new File(".").getAbsolutePath()为您提供应用程序的当前工作目录。我希望这回答了你的问题。