Java怎么获取Web服务器上文件的最后修改时间?

Java怎么获取Web服务器上文件的最后修改时间?,第1张

在JDK15+Eclipse32 下编译通过~
不过不能用URL判断WEB文件,只能坐在服务器上啦~
import javaio;
import javatext;
import javautil;
public class checkfile {
public checkfile(){

}
public long cfile(String fPath){
File nf=new File(fPath);
if(nfexists()){
return nflastModified();
}
return 0;
}
public static void main(String Args[]){
InputStreamReader isr = new InputStreamReader(Systemin);
BufferedReader br = new BufferedReader(isr);
String strBuf = null;
try{
strBuf = brreadLine();
}catch(IOException e){
eprintStackTrace();
}
checkfile cf=new checkfile();
SimpleDateFormat tm = new SimpleDateFormat("yyyy-mm-dd");
String tsm= tmformat(new Date(cfcfile(strBuftoString())));
Systemoutprintln("LastModified Time:" + tsm);
}
}

Step1:用户在地址栏输入一个网址,然后点击回车键;
Step2:浏览器与服务器建立TCP连接;
Step3:浏览器将用户的事件按照>把src保存到服务器数据库
走数据库直接访问表查询存放images字段就好了
后台:
//假设$res是你已经从数据库取出的值(已经遍历过了)
$dir = '根目录/public/images/';
echo '<img src='$dir$res'>';
在前台这样显示<img src='根目录/public/images/png'>

你把你的文件都放在E(你的猫目录):\apache-tomcat-6020\webapps\文件夹\你的所有文件,而访问的目录是你的id加端口号,如:19216800:8080/文件夹/指定的文件,你再放一个txt存放你的所有文件名(json),然后在客户端获取到文件列表的内容显示(json需解析),然后在列表监听事件中通过地址+动态的文件名,单击哪个就会下载那个了,请求的话可以使用>

下面提供二种方法会使用java发送url请求,并获取服务器返回的值

第一种方法:
代码如下:

import orgapache>

publicstaticStringsendUrlRequest(StringurlStr,Stringparam1,Stringparam2)throwsException{
StringtempStr=null;
>

//设置超时时间
>

//封装需要传递的参数
List<NameValuePair>nvps=newArrayList<NameValuePair>();
nvpsadd(newBasicNameValuePair("mainMemoCode",strmainMemoCode));
nvpsadd(newBasicNameValuePair("recordPassWord",strrecordPassWord));
//客户端的请求方法类型
>

//获取服务器返回>

//获取服务器返回页面的值
entity=responsegetEntity();
xmlContent=EntityUtilstoString(entity);
Stringstrmessage=null;
Systemoutprintln(xmlContent);
Systemoutprintln(responsegetHeaders("Content-Type")[0]getValue()toString());
>

}
catch(SocketTimeoutExceptione)
{
}
catch(Exceptionex)
{
exprintStackTrace();
}
finally{
>

代码如下:


publicstaticStringsendUrlRequest(StringurlStr,Stringparam1,Stringparam2)throwsException{

>

PrintWriterout=newPrintWriter(newOutputStreamWriter(connectiongetOutputStream(),"GBK"));
outprintln(param);
outclose();
BufferedReaderin=newBufferedReader(newInputStreamReader(connection
getInputStream(),"GBK"));

StringinputLine;

while((inputLine=inreadLine())!=null){
bankXmlBufferappend(inputLine);
}
inclose();
tempStr=bankXmlBuffertoString();
}
catch(Exceptione)
{
Systemoutprintln("发送GET请求出现异常!"+e);
eprintStackTrace();

}finally{
if(url_con!=null)
url_condisconnect();
}

returntmpeStr;
}

总结:多练习代码,熟练之后才能更快速的去了解代码的学习的方法。多去获取一些思维方面的书籍可以看看。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10365912.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-08
下一篇 2023-05-08

发表评论

登录后才能评论

评论列表(0条)

保存