Writing inside Mac application package/folder with Java

流过昼夜 提交于 2019-12-02 04:38:18

问题


Okay, I have thought before asking this question because at first it does sound like the age old question that boils down to "is it possible to write inside of an archive". I am new to Mac OS X but I have read that applications are just a folder with the .app extension and a specific file structure. So, I would like to know if it is possible to write inside of this folder, and if so how.

The reason I ask is because in my Java program, on windows, it reads some files that are in the programs directory (the principle of Program Files) but on OSX applications don't seem to create any files (that are apparent) - so I guessed that they must store them in the .app folder! If I assumed wrong though, I'd like to know where applications normally store the files that they create please.

Thanks in advance

EDIT The whole reason I ask this question is because I fear negative feedback if my application leaves files behind, so really I need informative opinions. In short, my application needs a configuration file, but it also allows users to create their own 'databases'. I now think that I will store these in the user's document folder, but I'm not sure as to whether I should delete these files when the app is deleted or just leave them. Obviously, deleting them would require me to make a package - which would just be an extra step for the user, so what do you think?... Oh yes, and the applications generates a license file upon the user entering a valid serial key - on Windows the information is stored in the registry, but on Mac I am not sure where to put the file containing this information! Any help would be much appreciated.


回答1:


You shouldn't write to the app bundle. Some reasons in no particular order:

  • The user may not have permissions to write to it. In fact, the app bundle can be on read-only media.

  • The app bundle is not specific to the user. It is likely to be in a shared location and used by all the users on the system.

  • Apps should be codesigned and modifying their internals is likely to invalidate the signature.

The appropriate place to put user data is either in the user's Documents folder, in a product-specific subdirectory of ~/Library/Application Support (or, if it should be system-wide, /Library/Application Support), or in a location that the user chooses.

I wouldn't be too concerned about leaving files behind if the user removes the app. It's pretty common and even desirable. For example, if I delete the old version before installing the new version, I want the new version to find the existing files left over from the old version. If you follow typical conventions, the user will know how to clean up (or something like AppZapper will be able to do so for them).




回答2:


I am searching the answer for this question by myself but I think I can help you with your problem. I have ported a "windows" java application by myself. I am no real Mac expert but my research on this topic gave me the following answers:

I understand the *.app folder as the installation package of your program. The internals of this folder are not shown to the user. For him it is simply the app. A quick google search gave me the following hints:

http://developer.apple.com/library/mac/#qa/qa1170/_index.html

where to put application data and temp files on mac

maybe this helps



来源:https://stackoverflow.com/questions/10127714/writing-inside-mac-application-package-folder-with-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!