包括在Eclipse Android项目的本地.json文件 [英] Include local .json file in Eclipse Android project
问题描述
我有一个本地.json文件。我不希望它是一台服务器上,我只是希望它被包含在我的应用程序。我试图直接粘贴到Eclipse在我的项目,但我得到了一个FileNotFoundException异常,我也试图把它粘贴在Windows资源管理器/搜索器的工作区文件夹,得到了同样的异常。我应该在哪里放呢?
I have a local .json file. I don't want it to be on a server, I just want it to be included in my app. I tried to paste it directly into Eclipse in my project, but I got a FileNotFoundException, I also tried to paste it in the workspace folder in Windows Explorer/Finder and got the same exception. Where should I put it?
谢谢!
推荐答案
您应该把文件无论是在 /资产
或 / RES /原料
目录你的Android项目。从那里,你可以检索其与任一: Context.getResources()openRawResource(R.raw.filename)
或 Context.getResources()。 getAssets()。打开(文件名)
。
You should put the file either in the /assets
or /res/raw
directory of your Android project. From there, you can retrieve it with either: Context.getResources().openRawResource(R.raw.filename)
or Context.getResources().getAssets().open("filename")
.
这篇关于包括在Eclipse Android项目的本地.json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!