Run the bat command in java to obtain the creation time of a windows file and the bat creation time.
Original article: run the bat command in java to obtain the creation time of a windows File
Code: 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 workfor (int i = 0; i < 6; i++) {data = br.readLine();}System.out.println("Extracted value : " + data);// split by spaceStringTokenizer st = new StringTokenizer(data);String date = st.nextToken();// Get dateString time = st.nextToken();// Get timeSystem.out.println("Creation Date : " + date);System.out.println("Creation Time : " + time);} catch (IOException e) {e.printStackTrace();}}}
Tags: java windows bat creation time topics: Text parsing and file processing scripts and tools
How to use the bat command to obtain the creation time of a file
Dir: add the/tc parameter to the file creation time.
@ Echo off
Set p = d: \ test
Set fn1_123.txt
Pushd % p %
For/f % I in ('dir/tc ^ | findstr/iec: "% fn %" ') do set t = % I
If "% t %" neq "2011-10-08" echo error !!!
How to Use the bat file to run Java programs in Windows
For the jar file java-jar *. jar
Currently, make sure that your classpath is correct and the path of the jar file is