简体   繁体   English

在Java代码中嵌入数据文件

[英]Embed datafile in java code

I have a dictionary file that is being used for word matching, the java code is to be submitted online and get executed.(for a online coding competition) How would I be able to use the dictionary data file, while my program executes online. 我有一个用于单词匹配的字典文件,该Java代码将在线提交并执行。(用于在线编码竞赛)当我的程序在线执行时,我将如何使用字典数据文件。 could it be embedded in the source code as compressed byte stream? 可以将其作为压缩字节流嵌入到源代码中吗? please suggest 请建议

There are multiple ways to achieve this: 有多种方法可以实现此目的:

  • either refer to the dictionairy file as a remote resource in your code. 在您的代码中,都可以将dictionairy文件称为远程资源。 This means that you ll most your dictionary file on a different online location which is well known by your online application code. 这意味着您将大部分词典文件放在在线应用程序代码众所周知的其他在线位置上。 You can then download the dictionary file and cache the file in memory for usage 然后,您可以下载字典文件并将其缓存在内存中以备使用

  • You can encode the dictionary file (for instance in Base64 encoding - to take care of special characters in the dictonary file) as a predefined datastructure / buffer in your code. 您可以将字典文件编码(例如,使用Base64编码-在字典中保留特殊字符),作为代码中的预定义数据结构/缓冲区。 This means however that you need to convert your dictionary file & rebuild your application each time you adapt the dictionary file. 但是,这意味着您每次修改字典文件时都需要转换字典文件并重建应用程序。

Pointing to a different "online" location would seem to more suitable solution. 指向不同的“在线”位置似乎是更合适的解决方案。

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

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