简体   繁体   English

用于在 java 的 os 文件系统级别管理文件的标准解决方案?

[英]standard solution for managing files in os file system level for java?

i am working on a web application.we are using java and jsp to upload user files on server and then do some management tasks on them, like checking that every one has only one profile picture (it is not a portal) or there should be only one folder for each user that contains all of its data.我正在开发一个 web 应用程序。我们正在使用 java 和 jsp 在服务器上上传用户文件,然后在它们上执行一些管理任务,例如检查每个门户网站或应该只有一个配置文件图片)每个用户只有一个文件夹包含其所有数据。 so is there any accepted solution, or manifest on how some one should do this, where to use db over file system and so on?那么是否有任何公认的解决方案,或者关于某人应该如何做到这一点的清单,在哪里使用 db over 文件系统等等? thnx谢谢

The traditional way of doing, in my experience, it to put all the structured and textual information in database.根据我的经验,传统的做法是将所有结构化和文本信息放入数据库中。

Binary files as images, videos, sounds, etc. can be stored in database, but since they can't be queried and are more easily served and backed up from the file system, they're often stored as files.图像、视频、声音等二进制文件可以存储在数据库中,但由于它们不能被查询并且更容易从文件系统提供和备份,它们通常被存储为文件。

If you are using relational DB do not store files there.如果您使用的是关系数据库,请不要在其中存储文件。 It is possible but it does not might overload your DB.这是可能的,但它不会使您的数据库过载。 Better way is to store files in file system and references to theses files in DB.更好的方法是将文件存储在文件系统中,并将这些文件的引用存储在数据库中。

Concerning the directories.关于目录。 If your system is relatively small you can store files in user dedicated directories.如果您的系统相对较小,您可以将文件存储在用户专用目录中。 It is very convenient for debugging and for implementation of some features like retrieving list of files per user or removing user.这对于调试和实现某些功能(例如检索每个用户的文件列表或删除用户)非常方便。 The disadvantage of this approach is scalability.这种方法的缺点是可扩展性。 File systems typically cannot effectively work with directories that contain millions of files.文件系统通常不能有效地处理包含数百万个文件的目录。 So the more scalable solution is to create hierarchical structure of directories and fill them until number of files reaches certain threshold, eg 10000 files.所以更具可扩展性的解决方案是创建目录的层次结构并填充它们,直到文件数量达到某个阈值,例如 10000 个文件。 In this case create new directory.在这种情况下,创建新目录。

If you create 3-5 levels deep directory structure it is scalable enough.如果您创建 3-5 级深度目录结构,则它具有足够的可扩展性。 Still references to the files are stored in DB.对文件的仍然引用存储在 DB 中。 So you can always retrieve files belonging to user utilizing query like因此,您始终可以使用以下查询检索属于用户的文件

select path from files where user=USER_ID

then iterate over this list in Java and read files if you need.然后在 Java 中遍历此列表并在需要时读取文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM