/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_fileText_fileRead */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>#ifndef _Included_com_fileText_fileRead
#define _Included_com_fileText_fileRead
#ifdef __cplusplus#include "fileReader.h"fileReader m_reader;jstring chartojstring( JNIEnv* env, char* pat )
{
//__android_log_print(ANDROID_LOG_WARN, "wuzhenhua", "change1");
jclass strClass = env->FindClass("java/lang/String");
jmethodID ctorID = env->GetMethodID(strClass, "<init>", "([BLjava/lang/String;)V");
jbyteArray bytes = env->NewByteArray(strlen(pat));
env->SetByteArrayRegion(bytes, 0, strlen(pat), (jbyte*)pat);
jstring encoding = env->NewStringUTF("UTF-8");
return (jstring)env->NewObject(strClass, ctorID, bytes, encoding);
}extern "C" {
#endif/*
* Class: com_fileText_fileRead
* Method: loadFile
* Signature: (Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_com_fileText_fileRead_loadFile
(JNIEnv *env, jobject, jstring filePath)
{
char *file =(char*)env->GetStringUTFChars(filePath,0);
return m_reader.loadFile(file);
}/*
* Class: com_fileText_fileRead
* Method: GetBuf
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT jstring JNICALL Java_com_fileText_fileRead_GetBuf
(JNIEnv *env, jobject, jint size)
{
char *buffer = new char[size];
memset(buffer,0,size);
m_reader.GetfileBuf(buffer);
jstring buf = chartojstring(env,buffer);
char *file =(char*)env->GetStringUTFChars(buf,0);
FILE *fp =NULL;
fp = fopen("/sdcard/110.txt","wr");
fwrite(file,sizeof(char),strlen(file),fp);
fclose(fp);
return buf;
}#ifdef __cplusplus
}
#endif
#endif目的是在Eclipse 端传文件路径,C++端读数据再返回回去;
fileReader 是C++的一个类,没问题。
通过测试当读txt文档时,可以通过测试,但是当我读png图片时,返回的是前几个字节,不完整,
我怀疑是chartojstring()这个函数出问题了,懂得人帮看看。
#include <jni.h>
/* Header for class com_fileText_fileRead */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>#ifndef _Included_com_fileText_fileRead
#define _Included_com_fileText_fileRead
#ifdef __cplusplus#include "fileReader.h"fileReader m_reader;jstring chartojstring( JNIEnv* env, char* pat )
{
//__android_log_print(ANDROID_LOG_WARN, "wuzhenhua", "change1");
jclass strClass = env->FindClass("java/lang/String");
jmethodID ctorID = env->GetMethodID(strClass, "<init>", "([BLjava/lang/String;)V");
jbyteArray bytes = env->NewByteArray(strlen(pat));
env->SetByteArrayRegion(bytes, 0, strlen(pat), (jbyte*)pat);
jstring encoding = env->NewStringUTF("UTF-8");
return (jstring)env->NewObject(strClass, ctorID, bytes, encoding);
}extern "C" {
#endif/*
* Class: com_fileText_fileRead
* Method: loadFile
* Signature: (Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_com_fileText_fileRead_loadFile
(JNIEnv *env, jobject, jstring filePath)
{
char *file =(char*)env->GetStringUTFChars(filePath,0);
return m_reader.loadFile(file);
}/*
* Class: com_fileText_fileRead
* Method: GetBuf
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT jstring JNICALL Java_com_fileText_fileRead_GetBuf
(JNIEnv *env, jobject, jint size)
{
char *buffer = new char[size];
memset(buffer,0,size);
m_reader.GetfileBuf(buffer);
jstring buf = chartojstring(env,buffer);
char *file =(char*)env->GetStringUTFChars(buf,0);
FILE *fp =NULL;
fp = fopen("/sdcard/110.txt","wr");
fwrite(file,sizeof(char),strlen(file),fp);
fclose(fp);
return buf;
}#ifdef __cplusplus
}
#endif
#endif目的是在Eclipse 端传文件路径,C++端读数据再返回回去;
fileReader 是C++的一个类,没问题。
通过测试当读txt文档时,可以通过测试,但是当我读png图片时,返回的是前几个字节,不完整,
我怀疑是chartojstring()这个函数出问题了,懂得人帮看看。
解决方案 »
- android 平台如何实现对PDF文件的编辑操作
- android 4.0怎样实现开机自启动服务,没有activity 急!急!急!哪位大神帮帮忙,谢了
- 自定义title的问题
- ImageView 何时可以提取 Bitmap
- launcher问题 退出闪现主屏
- 奇怪,Android应用中在手机充电时运行正常,电池供电不能运行。为什么?
- 子线程如何异步更新Fragment的UI界面
- 各位牛人,为什么在2.3上正常工作的拍照应用在4.3上崩溃?
- android 自定义相机问题。
- 关于android 6.0 的问题
- eclipse 如何导入新浪微博的java sdk
- android的测试时候,需要在AndroidManifest.xml文件里添加什么?
2,注意编码问题
应该用byte 对应你的数据,而不是用string。
png文件你还要怎么解析?可以直接转成对应的bitmap对象