java怎么获取文件访问时间
1个回答
展开全部
Java code
try { Process p = Runtime.getRuntime().exec( "cmd /C dir F:\\test4\\a2.html /tc");//这个地方的\\不能用/替代 InputStream is = p.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String result; String getTime = null; while ((result = br.readLine()) != null) { String[] str = result.split(" "); for (int i = str.length - 1; i >= 0; i--) { if (str[i].equals("a2.html")) { getTime = str[0] + " " + str[2]; } } } System.out.println("a2.html 文件的创建日期是:" + getTime); } catch (java.io.IOException exc) { exc.printStackTrace(); } // String ss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format((new File("F:\\test4\\a2.html").lastModified())); System.out.println("最后修改时间:"+ss);
try { Process p = Runtime.getRuntime().exec( "cmd /C dir F:\\test4\\a2.html /tc");//这个地方的\\不能用/替代 InputStream is = p.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String result; String getTime = null; while ((result = br.readLine()) != null) { String[] str = result.split(" "); for (int i = str.length - 1; i >= 0; i--) { if (str[i].equals("a2.html")) { getTime = str[0] + " " + str[2]; } } } System.out.println("a2.html 文件的创建日期是:" + getTime); } catch (java.io.IOException exc) { exc.printStackTrace(); } // String ss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format((new File("F:\\test4\\a2.html").lastModified())); System.out.println("最后修改时间:"+ss);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询