简体   繁体   English

如何将现有文件夹添加到android并使用它们?

[英]How to add existing folder to android and use them?

I am developing a mobile application by using Lucene. 我正在使用Lucene开发移动应用程序。 I have a folder which includes index files. 我有一个包含索引文件的文件夹。 In the application, I want to use these index files for searching. 在应用程序中,我想使用这些索引文件进行搜索。 Lucene Library expects path of this folder to read. Lucene Library希望读取此文件夹的路径。 I placed this folder in the assets folder. 我将此文件夹放置在资产文件夹中。 But I can't get this folder's path. 但是我找不到该文件夹​​的路径。 I checked Android Storage Documentation. 我查看了Android存储文档。 But I could not find any solution to add existing folder to external storage. 但是我找不到将现有文件夹添加到外部存储的任何解决方案。 If I would add them to external storage, I can get the path with getExternalFilesDir() . 如果将它们添加到外部存储中,则可以使用getExternalFilesDir()获取路径。 I am working by using emulator. 我正在使用模拟器进行工作。

Directory dir = FSDirectory.open(Paths.get("path of index folder"));
IndexReader reader = DirectoryReader.open(dir);
searcher = new IndexSearcher(reader);

Above code section works well in a Java SE application since I can give the path of folder directly. 上面的代码部分在Java SE应用程序中效果很好,因为我可以直接给出文件夹的路径。 But In android I am working by using emulator. 但是在android中,我正在使用模拟器进行工作。 How can give path of index folder in android? 如何在Android中给出索引文件夹的路径? Where should I place this folder to reach in the application? 我应该将该文件夹放置在应用程序中的什么位置?

You put them into the folder into your assets, then copy the assets to the file system on first run. 您将它们放到资产的文件夹中,然后在第一次运行时将资产复制到文件系统。 Then you can pass the location you wrote them to to Lucene. 然后,您可以将您编写它们的位置传递给Lucene。

Fair warning: I tried to use Lucene and couldn't a year ago, because it was using IO functions that weren't ported to Android. 合理的警告:一年前,我曾尝试使用Lucene,但不能,因为它使用的是未移植到Android的IO功能。 Now that Java 1.8 exists on Android maybe they have been, but if not you're going to have additional problems to solve. 既然Java 1.8在Android上已经存在,也许已经存在了,但是如果没有,那么您将要解决其他问题。

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

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