欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java运行bat命令得到某个windows文件的创建时间

程序员文章站 2022-05-08 16:01:14
...

原文:java运行bat命令得到某个windows文件的创建时间

代码下载地址:http://www.zuidaima.com/share/1550463260150784.htm

 

package com.zuidaima.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
 * 
 * @author zuidaima.com
 * 
 */
public class GetFileCreationDate {
	public static void main(String[] args) {

		try {
			Process proc = Runtime.getRuntime().exec(
					"cmd /c dir c:\\zuidaima_com_logfile.log /tc");

			BufferedReader br = new BufferedReader(new InputStreamReader(
					proc.getInputStream()));

			String data = "";

			// it's quite stupid but work
			for (int i = 0; i < 6; i++) {
				data = br.readLine();
			}

			System.out.println("Extracted value : " + data);

			// split by space
			StringTokenizer st = new StringTokenizer(data);
			String date = st.nextToken();// Get date
			String time = st.nextToken();// Get time

			System.out.println("Creation Date  : " + date);
			System.out.println("Creation Time  : " + time);

		} catch (IOException e) {

			e.printStackTrace();

		}

	}
}

标签: java windows bat 创建时间话题: 文本解析和文件处理 脚本和工具