Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

File Creation Date using JNI

Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
How can I get the creation date of a file using JNI ? Examples are always welcome !
Thanx !
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);

System.loadLibrary(<libraryfile> ;
catch(Exception exp){exp.printStackTrace();}

public static void main(String args[])
if(args.length < 1)
System.out.println("Usage: sample <filename>");

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" {
* Class: sample
* Method: getCreateDate
* Signature: (Ljava/lang/String Ljava/lang/String;
JNIEXPORT jstring JNICALL Java_sample_getCreateDate
(JNIEnv *, jclass, jstring);
#ifdef __cplusplus
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

CString strCreateDate = ""; //format the create date obtained from CFileFind

int len = strCreateDate.getLength();

char* pCreateDate = strCreateDate.getBuffer();

jstring createDate = NewString(env, pCreateDate, len);


pCreateDate = NULL;

return createDate;
In case of any clarifications refer to JNI specifiactions available with JDK documentation.
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic