包括在Eclipse Android项目的本地.json文件 [英] Include local .json file in Eclipse Android project

查看:115
本文介绍了包括在Eclipse Android项目的本地.json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地.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 /原料目录你的Andr​​oid项目。从那里,你可以检索其与任一: 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屋!

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