hi i just wanted to parse a file to find certain associated data
for ex if my text file is :
<!#first>This is string1
<!second>THis is string2
So if user types in first...he will get This is string 1
iv written a simple C++ code to parse the text file
but now i need to call that native code from a java source
i tried to write the native function but dont have much idea abt JNI so could someone help me out pls...

jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
jobject thiz,jstring javaString )
{



using namespace std;
const char *nativeString = env->GetStringUTFChars(javaString, 0);
string val1,val2;
string inp(nativeString);
cout<<"enter:";
cin>>inp;
string line;
ifstream myfile ("data.txt");
if(myfile.is_open())
{
while(!myfile.eof())
{
getline(myfile,line,'<');

istringstream iss1(line);
getline(iss1,val1,'>');
val1.erase(0,2);
getline(iss1,val2);

if(inp.compare(val1)==0)
cout<<"\n Our returned string is : "<<val2;
}
}
char buffer[20]
strcpy(buffer, val2.c_str());


return *env->NewStringUTF(env, buffer);

}

From what I've heard, calling native code using JNI is a real PITA. Look into alternatives like JNA and Swig for easing this integration task.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.