Hi,
Here is some sample illustration regarding getting the file create time using JNI.
I have assumed that the native code is done using VC++. I have not compiled the c++ code.
public class sample
{
public static native
String getCreateDate(String filename);
static
{
try
{
System.loadLibrary(<libraryfile>
;
}
catch(Exception exp){exp.printStackTrace();}
}
public static void main(String args[])
{
if(args.length < 1)
{
System.out.println("Usage: sample <filename>");
return;
}
String filename = args[0];
String createDate = getCreateDate(filename);
System.out.println("The file :"+filename+" is created at - "+createDate);
}
}
//------------------------
//C File Header
//------------------------
/* The Header file that has to be used while writting the native code accessible
from
java.
generated using : javah sample
*/
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class sample */
#ifndef _Included_sample
#define _Included_sample
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: sample
* Method: getCreateDate
* Signature: (Ljava/lang/String
Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_sample_getCreateDate
(JNIEnv *, jclass, jstring);
#ifdef __cplusplus
}
#endif
#endif
Implementation for the native method Illustrated for VC++
---------------------------------------------------------
JNIEXPORT jstring JNICALL Java_sample_getCreateDate
(JNIEnv * env, jclass cls, jstring filename)
{
CString strFilename = new CString(GetStringChars(env, filename, JNI_FALSE));
//Please refer to MSDN regarding this
//
CFileFind::GetCreationTime()
CString strCreateDate = ""; //format the create date obtained from CFileFind
int len = strCreateDate.getLength();
char* pCreateDate = strCreateDate.getBuffer();
jstring createDate = NewString(env, pCreateDate, len);
strCreateDate.releaseBuffer();
pCreateDate = NULL;
return createDate;
}
In case of any clarifications refer to JNI specifiactions available with JDK documentation.
------------------
Vijay.