原文: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 创建时间话题: 文本解析和文件处理 脚本和工具
java运行bat命令得到某个windows文件的创建时间
时间: 2024-11-05 14:42:24