
Java怎么获取Web服务器上文件的最后修改时间?
1个回答
展开全部
在JDK1.5+Eclipse3.2 下编译通过~
不过不能用URL判断WEB文件,只能坐在服务器上啦~
import java.io.*;
import java.text.*;
import java.util.*;
public class checkfile {
public checkfile(){
}
public long cfile(String fPath){
File nf=new File(fPath);
if(nf.exists()){
return nf.lastModified();
}
return 0;
}
public static void main(String Args[]){
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String strBuf = null;
try{
strBuf = br.readLine();
}catch(IOException e){
e.printStackTrace();
}
checkfile cf=new checkfile();
SimpleDateFormat tm = new SimpleDateFormat("yyyy-mm-dd");
String tsm= tm.format(new Date(cf.cfile(strBuf.toString())));
System.out.println("LastModified Time:" + tsm);
}
}
不过不能用URL判断WEB文件,只能坐在服务器上啦~
import java.io.*;
import java.text.*;
import java.util.*;
public class checkfile {
public checkfile(){
}
public long cfile(String fPath){
File nf=new File(fPath);
if(nf.exists()){
return nf.lastModified();
}
return 0;
}
public static void main(String Args[]){
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String strBuf = null;
try{
strBuf = br.readLine();
}catch(IOException e){
e.printStackTrace();
}
checkfile cf=new checkfile();
SimpleDateFormat tm = new SimpleDateFormat("yyyy-mm-dd");
String tsm= tm.format(new Date(cf.cfile(strBuf.toString())));
System.out.println("LastModified Time:" + tsm);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询