Creating a directory/folder on a mac

+1 Cem Saglam · August 20, 2014

I'm extremely new in using a mac, so I'm not good with directories, pathnames etc. (a minute to laugh)
Simply, all I want to do is to create a .txt file in which I'll store data. On windows I can just store that in C:/stuff or something. Can you suggest a stable path name like C:/stuff for mac?

ps: may be an extremely simple/stupid question. Yet I literally know very little about mac.

Post a Reply


Oldest  Newest  Rating
+2 Cem Saglam · August 20, 2014
Firstly, sorry about the wrong post place. Since I was coding in Java I assumed it'd be fine, as I'm trying to create a directory. ^^'

I tried what you suggested, and it worked, so thanks!
BUT, assume I'll be sharing this program with other mac users. The folder will try to be created at <myusername>, but that is not the case in any other computer.
Any opinions on that?
+2 Cem Saglam · August 20, 2014
Yes, it does.
Let me put it this way, quoting what you typed:

/ is the root folder, it is equivalent of C: on windows.

/Users/<your username>

Say my username is abc.
I can create and handle my files using /Users/abc (ON MY COMPUTER), which is great.

BUT I'll be sharing this program with other computers. Other computers will not have abc as a username, they'll have something entirely different.

So whenever my program tries to access /Users/abc on another computer, it will not work, since that mac has an entirely different username. 

Hence I need something like this:


Is my problem clearer?
+1 Cem Saglam · August 20, 2014
Sorry, but still something doesn't add up.

Say my username is abc. And my code will be creating text files with data in them, at a directory called myProgram.

Hence I'm assuming /Users/abc/myProgram is the general place where the text files will be created via the code.
BUT, here is my question: the code will try to create text files in /Users/abc/myProgram

Will the fact that other mac's have different usernames (other than abc) not create a problem with the way I create my directory? Won't the code try to access abc and fail? (since it's not there to be found)
+1 Aubree Keegan · August 21, 2014
Can you post your code?
0 Çağlan Turgut · August 21, 2014
You can use 

String uname = System.getenv("USER");

to get to username and put to the place of "abc" but I think using the path that program runs on is much more safe .


You can see the relative path by typing:

String filename = new File("").getAbsolutePath(); 
+1 Cem Saglam · August 23, 2014
I solved most of the problem. The program is now compatible to mac, with a minor bug.
Thanks for all your help, guys.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator