android下 assets文件夹下sqlite数据库资源及其他资源问题

string path = “mydatabase.sqlite”;
string o_path=CCFileUtils::getWriteablePath()+path;
unsigned long size=0;
unsigned char *data=CCFileUtils::getFileData(path.c_str(),“r”,&size);//reinterpret_cast<char *>
const char *c_data=reinterpret_cast<char *>(data);
ofstream os(o_path.c_str(), ios::binary);
os.write(c_data,strlen(c_data));

这样是可以读到sqlite文件里面的东西,但是只有前面15个字符串的东西,后面的就读不出来了,可能是sqlite作了些保密性的限制?只可以读出“SQLite format 3”,后面就没有了

— Begin quote from ____

LeoCocos 发表于 2012-6-20 13:01 url

别把二进制的数据转成字符串处理

— End quote

那应该怎么处理呢?

— Begin quote from ____

LeoCocos 发表于 2012-6-20 13:01 url

别把二进制的数据转成字符串处理

— End quote

谢谢您的回复

请问我在ios下怎么把数据库的文件拷进手机呢?在程序安装的时候。。。。要不然我的据对路径怎么访问到数据库呢?

这个问提也只是在多平台移植的时候会有,应为先前已经设置了sqllite。。。额

你这个问题解决了么?我现在也有这个问题

我在项目中上来就把资源中的db拷贝到writablepath中,然后我用的Kompex进行sqlite数据库的读写。这是工具的地址:http://sqlitewrapper.kompex-online.com/
在我的多开发环境已经配置成功(win32和android)。木有问题。(如果不进行复制,得到的位置好像是assets/mytest.db,这个地方跟你的问题一样,读不出)
上面用的的拷贝是这样写的:
void YFile::CopyFileToWriteablePath(const char * file) {
std::string strFile = file;
std::string strPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(strFile.c_str());
unsigned long len = 0;
unsigned char* data = NULL;
data = CCFileUtils::sharedFileUtils()->getFileData(strPath.c_str(),“r”,&len);

std::string destPath = CCFileUtils::sharedFileUtils()->getWritablePath();
destPath += strFile;

FILE *pFp = fopen(destPath.c_str(),"w+");
fwrite(data,sizeof(char), len, pFp);
fclose(pFp);
delete ] data;
data = NULL;

}

输入的file就是在Resources\目录下的数据库文件名"mytest.db",
函数可以复制这个文件到可读目录下 Android平台为 /data/data/org.HelloWorld.game/files/mytest.db