简体   繁体   English

如何在当前目录中保存文件?

[英]How can I save a file in the current directory?

I would like to know how to save a file in the current directory. 我想知道如何在当前目录中保存文件。 For example, let's say that the software application creates a text file called "Information.txt", and the software application allows this text file to be edited. 例如,假设软件应用程序创建了一个名为“ Information.txt”的文本文件,并且该软件应用程序允许对该文本文件进行编辑。 If I edit the text in this text file and save it, I would like to be able to copy the project onto a flash drive and use it on another computer, still having access to the "Information.txt" file. 如果我在此文本文件中编辑文本并将其保存,则希望能够将项目复制到闪存驱动器上,并在仍可访问“ Information.txt”文件的另一台计算机上使用它。

Basically, what I want to be able to do is save a file in the same directory as the project. 基本上,我想做的就是将文件保存在与项目相同的目录中。 What filepath would I use to do this. 我将使用什么文件路径来执行此操作。 And, if I was doing this with a database file, how might I go about saving the database in the current directory? 而且,如果我正在使用数据库文件执行此操作,该如何将数据库保存在当前目录中?

Thank you in advance for any helpful answers. 预先感谢您提供任何有用的答案。

Regards, 问候,

Ryan Shukis 瑞安·舒基斯(Ryan Shukis)

Assuming you know how to write to a file you can use the following: 假设您知道如何写入文件,则可以使用以下命令:

File file = new File(System.getProperty("user.dir") + yourPath);
FileOutputStream fos = new FileOutputStream(file);

The System.getProperty("user.dir") returns the current working directory. System.getProperty("user.dir")返回当前工作目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM