Janne
Janne

Reputation: 13

Java file directory for multiple users

i have a plugin which is going to be used more than one client, and the plugin has to access a file to load some arrays in java

fFile = new File("file path");

I want the path is general,

How can I declare a file path for more than one account? For example

" C:\users\X\documents\filename" and for another user

" C:\users\Y\documents\filename" or maybe something "C:\users\$username\documents\filename"

Upvotes: 0

Views: 560

Answers (3)

Snicolas
Snicolas

Reputation: 38168

You can use System.getProperty( "user.home" ) to get the home directory of users. And use that String to compose your path.

Regards, Stéphane

Upvotes: 1

Michael Berry
Michael Berry

Reputation: 72294

System.getProperty("user.home"); is what you want here - usually it returns the my documents folder on windows and /usr/home on *nix.

Upvotes: 1

Jigar Joshi
Jigar Joshi

Reputation: 240918

use user.home for this

String path = System.getProperty("user.home") + File.separator + "someFileName.txt";

Upvotes: 3

Related Questions