Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

danner26

macrumors newbie
Original poster
Jan 26, 2015
2
0
Hello,

I am a windows developer, but I need to get my program to be compatible on multiple platforms.

In windows, I usually save and create directories in AppData. Where is the best place to do so on a mac?

Also, I am use to creating a new directory, then the file using

Code:
     File file = new File(System.getenv("APPDATA") + "/Test");
     file.mkdirs();

     File file2 = new File(System.getenv("APPDATA") + "/Test/test.txt");
     file.createNewFile();
Please do not take this code as literal. There is a lot more implemented, I am just shorthanding this.

Is this the proper way to do so on the OSX platform ?


Thanks much,

Daniel
 
Last edited:
Hi,
1) save user data under /Users/{you},
2) conventional in OSX is that data is saved under Applications and Library
but if I were you I wouldn't mix data you don't know about with (your own)
data you do know about.
3) no problem to save your own stuff in (e.g.) /Users/{you}/MyData
or even /Users/{you}/AppData

Multi-platform programs are a drag: split MSWindows / UNIX like by the
directory path separator ('/' '\\')
;JOOP!
 
Example:

Code:
      if(File.separatorChar == '/')    // UNIX flavours.
      {
         if(new File("/Users").isDirectory()) // OSX.
         {
            // TODO
         }
         else                          // Other UNIX flavours.
         {
            // TODO
         }
      }
      else if(File.separatorChar == '\\') // MSWindows flavours.
      {
         if(new File("C:/Users").isDirectory()) // Windows 7, Vista.
         {
            // TODO
         }
         else
         {
            if(new File("C:/Documents and Settings/").isDirectory()) // Windows XP, NT.
            {
               // TODO
            }
            else                       // Any older Windows 98, ME, 2000
            {
               // TODO
            }
         }
      }
Probably quite not perfect for several UNIX/LINUX/BSD flavours .......
;JOOP!
 
While your basic idea seems reasonable, I would say that hard coding Windows paths to use the "C" drive is a pretty horrible idea.
I'm sure that Windows has methods/functions similar to NSFileManager -URLForDirectory:inDomain:appropriateForURL:create:error: and the
NSSearchPathDirectory locations - to find standard locations or the drive letter of the current boot drive, if Windows is installed on something odd like "D".
 
It was just an example, like the original post: don't take it literally.
Btw.: on my own computer my data live on D:\ , /D/ resp.

;JOOP!
 
It was just an example, like the original post: don't take it literally.
Btw.: on my own computer my data live on D:\ , /D/ resp.

;JOOP!

I kind of assumed so.

I mainly posted about this to avoid any readers getting the idea that this is a good way to do things.
 
Hey guys thanks for the response, but where you see the

System.getenv("APPDATA")

Puts the directory path in windows appdata location. I found my answer, it is the same, just the paths are different.

Thank you everyone who answered !
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.