jni C/C++ 头文件:MyFileTime.h
C/C++ code
/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class MyFileTime */
#ifndef _Included_MyFileTime
#define _Included_MyFileTime
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: MyFileTime
* Method: getFileCreationTime
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_MyFileTime_getFileCreationTime
(JNIEnv *, jclass, jstring);
#ifdef __cplusplus
}
#endif
#endif
-------------------------------------------------------------------------------
源文件:MyFileTime.c
C/C++ code
#include
#include "MyFileTime.h"
JNIEXPORT jstring JNICALL Java_MyFileTime_getFileCreationTime(JNIEnv *env, jclass cls, jstring FileName)
{
HANDLE hFile;
FILETIME creationTime;
FILETIME lastAccessTime;
FILETIME lastWriteTime;
FILETIME creationLocalTime;
SYSTEMTIME creationSystemTime;
jstring result;
char fileTimeString[30];
hFile = CreateFile((char *)env->GetStringUTFChars(FileName, 0), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(hFile == INVALID_HANDLE_VALUE) return env->NewStringUTF("");
if(GetFileTime(hFile, &creationTime, &lastAccessTime, &lastWriteTime))
{
if(FileTimeToLocalFileTime(&creationTime, &creationLocalTime))
{
if(FileTimeToSystemTime(&creationLocalTime, &creationSystemTime))
{
sprintf(fileTimeString,
"%d.%d.%d %d:%d:%d.%d\0",
creationSystemTime.wYear,
creationSystemTime.wMonth,
creationSystemTime.wDay,
creationSystemTime.wHour,
creationSystemTime.wMinute,
creationSystemTime.wSecond,
creationSystemTime.wMilliseconds);
result = env->NewStringUTF(fileTimeString);
}
else
result = env->NewStringUTF("");
}
else
result = env->NewStringUTF("");
}
else
result = env->NewStringUTF("");
CloseHandle(hFile);
return result;
}
-----------------------------------------------------------------------------------
精确到毫秒:
public final class MyFileTime {
static {
System.loadLibrary("MyFileTime");
}
private static native String getFileCreationTime(String fileName);
public static String getCreationTime(String fileName) {
return getFileCreationTime(fileName);
}
public static void main(String[] args) {
System.out.println(MyFileTime.getCreationTime("D:/modeldesign/MyStuff/MyFileTime.dll"));
}
}
结果是字符串:
2008.4.25 23:16:19.890(年.月.日 时:分:秒.毫秒)
=======================================================
其他方法 - -- 仅供参考
#include "stdio.h"
#include "windows.h"
void main(int argc,char** argv){
HFILE hFile;
OFSTRUCT lp;
FILETIME creationTime;
FILETIME lastAccessTime;
FILETIME lastWriteTime;
FILETIME creationLocalTime;
SYSTEMTIME creationSystemTime;
hFile = OpenFile(argv[1],&lp, OF_READ);
if(hFile == HFILE_ERROR)
{
printf("");
return;
}
if(GetFileTime((HANDLE)hFile, &creationTime, &lastAccessTime, &lastWriteTime))
{
if(FileTimeToLocalFileTime(&creationTime, &creationLocalTime))
{
if(FileTimeToSystemTime(&creationLocalTime, &creationSystemTime))
{
printf("%d.%d.%d-%d:%d:%d.%d\0",
creationSystemTime.wYear,
creationSystemTime.wMonth,
creationSystemTime.wDay,
creationSystemTime.wHour,
creationSystemTime.wMinute,
creationSystemTime.wSecond,
creationSystemTime.wMilliseconds);
return ;
}
}
}
printf("");
return ;
}
然后,Process p = Runtime.getRuntime().exec("cmd /c c:\\GetFileTime1.exe c:\\t1.txt");中再读取吧。否则怎办呢?
为方便你处理,将结果输出改为:2008.4.24-20:11:3.480 格式。
另:dir命令显示的最后修改的时间,而不是创建文件的时间。
以上仅供你参考。
Linux如何查找文件的创建时间
Linux的文件能否找到文件的创建时间取决于文件系统类型,在ext4之前的早期文件系统中(ext.ext2.ext3),文件的元数据不会记录文件的创建时间,它只会记录访问时间.修改时间.更改时间(状态 ...
Python 获取文件的创建时间,修改时间和访问时间
# 用到的知识# os.path.getatime(file) 输出文件访问时间# os.path.getctime(file) 输出文件的创建时间# os.path.getmtime(file) 输 ...
C#/.NET 读取或修改文件的创建时间和修改时间
手工在博客中添加 Front Matter 文件头可是个相当费事儿的做法,这种事情就应该自动完成. .NET 中提供了非常方便的修改文件创建时间的方法,使用这种方法,能够帮助自动完成一部分文件头的编写 ...
java操作文件的创建、删除、遍历
java操作文件的创建.删除.遍历: package test; import java.io.File; import java.io.IOException; import java.util.A ...
python文件夹遍历,文件操作,获取文件修改创建时间
在Python中,文件操作主要来自os模块,主要方法如下: os.listdir(dirname):列出dirname下的目录和文件os.getcwd():获得当前工作目录os.curdir:返回当前 ...
Linux 如何用命令查看binlog文件的创建时间
目录 背景 分析 方法 注意 背景 MySQL在26日 16:23:49产生了大量的慢查询,在这段时间内,binlog文件刷新的很快(查看慢日志是mysql DML并发比较多),想知道写完一个binl ...
python 修改文件的创建时间、修改时间、访问时间
目录 python 修改文件创建.修改.访问时间 方案一 方案二(无法修改文件创建时间) python 修改文件创建.修改.访问时间 突如其来想知道一下 python 如何修改文件的属性(创建.修改. ...
TDirectory.GetCreationTime、TDirectory.SetCreationTime获取和设置文件夹创建时间
使用函数: System.IOUtils.TDirectory.GetCreationTime//获取创建时间 System.IOUtils.TDirectory.SetCreationTime//设 ...
mysql保存当前时间精确到秒
用mybatis在mysql中保存字段精确到秒须要两个步骤. 1.如今mysql中将时间字段改为datetime 比如:alter table tablename add pay_date da ...
随机推荐
深入理解CSS中的长度单位
前面的话 本文分为绝对长度单位和相对长度单位来介绍CSS中的长度单位的主要知识 绝对长度单位 绝对长度单位代表一个物理测量 像素px(pixels) 在web上,像素px是典型的度量单位,很多其他长度 ...
Fragment 笔记
1.getActivity() 为null问题 在Fragment基类里设置一个Activity mActivity的全局变量,在onAttach(Activity activity)里赋值,使用m ...
C++与Java多态的区别
多态是指用父指针指向不同子类对象时,调用其共有的函数,不同的子类会有不同的行为.虽然C++和Java都具有多态机制,但是他们的实现不同,使用时的效果也会略有不同. 在C++中 普通函数调用:具体调用哪 ...
关于jQuery中的attr和data问题
今天在使用data获取属性并且赋值时遇到一个小问题,写下来防止以后再跳坑. 在使用jQuery获取自定义属性值时,我们习惯用 $(selector).attr('data-value'); jQuer ...
String类之substring--->;查找某位置对应的字
以下方法都是java内置类String类的内置方法(不是构造方法哦,就是普通的方法),不需要我们写,直接拿过来用即可. substring方法对应Api介绍 查找字符串中的 从int beginI ...
poj 3461 Oulipo(KMP模板题)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 36903 Accepted: 14898 Descript ...
MySQL数据库使某个不是主键的字段唯一
在使用MySQL数据的过程中有时候我们须要某个不是主键的字段不反复.这个时候就要用到SQL的UNIQUE约束了. 以下摘抄自w3school里的一段介绍: UNIQUE 约束唯一标识数据库表中的每条记 ...
12306登录爬虫 cookies版本
import requests import re import base64 cookies = None # 进入主页,保留cookies login_url = 'https://kyfw.12 ...
C#设计模式--状态模式
设计模式: 状态模式(State Pattern) 简单介绍: 在状态模式(State Pattern)中,类的行为是基于它的状态改变的.这种类型的设计模式属于行为型模式. 在状态模式中,我们创建表示 ...
Unicode编码:保存中文cookie
中文和英文字符不同,中文属于Unicod字符,在内存中站4个字符,而英文属于ASCII字符,内存中只占2个字符.Cookie中使用Unicode字符时需要对Unicode字符进行编码,否则会乱码.编码 ...