Ryan
Ryan

Reputation: 531

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. 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.

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

Upvotes: 2

Views: 5290

Answers (1)

nullByteMe
nullByteMe

Reputation: 6391

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.

Upvotes: 1

Related Questions