用Java在Mac应用程序包/文件夹中编写 [英] Writing inside Mac application package/folder with Java

查看:142
本文介绍了用Java在Mac应用程序包/文件夹中编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在问这个问题之前就已经想过,因为起初听起来确实像是一个古老的问题,可以归结为是否有可能在存档中写入内容".我是Mac OS X的新手,但我已经读到应用程序只是一个扩展名为.app且具有特定文件结构的文件夹.因此,我想知道是否可以在此文件夹中写入内容,以及如何写入.

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.

我问的原因是因为在我的Java程序中,在Windows上,它会读取程序目录中的某些文件(程序文件"的原理),但是在OSX应用程序上似乎没有创建任何文件(很明显) )-因此我猜想它们必须将它们存储在.app文件夹中!如果我以为是错的话,我想知道应用程序通常在哪里存储他们创建的文件.

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.

预先感谢

编辑我之所以问这个问题,是因为我担心如果我的应用程序留下了文件,则会产生负面反馈,所以我确实需要翔实的见解.简而言之,我的应用程序需要一个配置文件,但它也允许用户创建自己的数据库".我现在认为我将这些文件存储在用户的文档文件夹中,但是我不确定在删除应用程序时应该删除这些文件还是直接保留它们.显然,删除它们将需要我制作一个软件包-这对用户来说只是一个额外的步骤,所以您怎么看?...哦,是的,当用户输入有效的序列号时,应用程序会生成许可证文件-在Windows上,信息存储在注册表中,但是在Mac上,我不确定将包含此信息的文件放在何处!任何帮助将不胜感激.

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.

推荐答案

您不应该写入应用程序捆绑包.某些原因没有特别的顺序:

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.

放置用户数据的适当位置是在用户的Documents文件夹中,在〜/Library/Application Support的特定于产品的子目录中(或者,如果是系统范围,则在/Library/Application Support中),或者在用户选择的位置.

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.

如果用户删除应用程序,我不会太担心将文件留在后面.这是很普遍的,甚至是可取的.例如,如果我在安装新版本之前删除了旧版本,则希望新版本查找旧版本剩余的现有文件.如果您遵循典型的约定,则用户将知道如何清理(或者类似AppZapper这样的清理).

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

这篇关于用Java在Mac应用程序包/文件夹中编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆