请教各位大侠:如何用java监控ftp服务器的特定文件夹是否有新文件上传?? 用一个线程来监控这个folder,用一个文件或者数据库来记录你上一次扫描的时间,然后如果扫描到有文件的last modify time迟过你上一次扫描时间的话......如果你每次扫描后把文件搬到另一个目录就更简单了...... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 其实就是设置一个对文件夹中文件的检测嘛!你每次把里面的文件名称全部存在一个容器里面(在java中有vector),然后获取及时的全部文件名称与之比较,如果里面没有就是新的那! /* * Created on 2004/06/17 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */package playoffs.test.ftp;import java.io.IOException;import java.io.InputStream;import java.net.MalformedURLException;import java.net.URL;import sun.net.ftp.FtpClient;import sun.net.www.protocol.ftp.FtpURLConnection;/** * @author wangji * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */public class FtpTest { private FtpURLConnection ftpConn; private FtpClient ftpClient; private URL url; public FtpTest(){ try { ftpClient = new FtpClient("xxx.xxx.xxx.xxx"); } catch (IOException e) { e.printStackTrace(); } try { ftpClient.login("xxxxx","xxxxxx"); } catch (IOException e2) { e2.printStackTrace(); } try { ftpClient.ascii(); } catch (IOException e1) { e1.printStackTrace(); } try { ftpClient.cd("xxxx/log"); } catch (IOException e3) { e3.printStackTrace(); } InputStream in = null; try { in = ftpClient.list(); } catch (IOException e4) { e4.printStackTrace(); } int x = 0; try { x = in.read(); } catch (IOException e5) { e5.printStackTrace(); } while(x!=-1){ System.out.print((char)x); try { x = in.read(); } catch (IOException e6) { e6.printStackTrace(); } }// System.out.println(ftpClient.list().toString()); String str = ftpClient.getResponseString(); System.out.println(str); System.out.println("finish"); try { url = new URL("ftp://xxx.xxx.xxx.x/xxxx/log/xxxxx.log"); } catch (MalformedURLException e6) { e6.printStackTrace(); } try { ftpConn = (FtpURLConnection) url.openConnection(); } catch (IOException e9) { e9.printStackTrace(); } try { InputStream reader = ftpConn.getInputStream(); } catch (IOException e7) { e7.printStackTrace(); } } public static void main(String[] args){ new FtpTest(); }} 支持 Arias(永恒之道) ( ) 的说法。 一个本地监听的大体思路File f = new File(root) //root,要查看的目录while(true){ String[] fn = f.list(); //获取所有子File对象 File tmp = null; for(int i=0;i<fn.length();i++){ tmp = new File(fn[i]) if(tmp.isDirectory()){ 继续朝下走两步 }else{ 是文件了..入库入库,查查看以前有没有 if(o,new.file 新文件){ 新来的,整吧.... } } } //扫完了...太累了,改休息一下了 try{ Thread.sleep(1000*60); //让俺睡一分钟吧..整的累了 }catch(Exception e){}} 运行不了,但是不明白提示的意思 解析邮件地址 请教如何在一个java程序中启动另一个java程序 java不是一个可视化的开发环境,界面也要用代码写,我的理解对吗? 如何用 Java 编写捕捉 adsl 上网时得到的的动态 IP 地址 ? 关于连接数据库时遇到的一个紧急问题,全公司都无法解决 关于JPopupMenu的问题,请大家帮帮忙,谢谢。 各位高手: 接收到的数据已知道具体类型 但是不知道如何转换 哪位用过 Ronald Tschalär 的 HTTPClient package? 怎么样? 怎样把分页的pdf文件合并??? 如何读写汉字和英文的混排? 在线等答案,马上结帖!
你每次把里面的文件名称全部存在一个容器里面(在java中有vector),然后获取及时的全部
文件名称与之比较,如果里面没有就是新的那!
* Created on 2004/06/17
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package playoffs.test.ftp;import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;import sun.net.ftp.FtpClient;
import sun.net.www.protocol.ftp.FtpURLConnection;/**
* @author wangji
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class FtpTest { private FtpURLConnection ftpConn;
private FtpClient ftpClient;
private URL url; public FtpTest(){ try {
ftpClient = new FtpClient("xxx.xxx.xxx.xxx");
} catch (IOException e) {
e.printStackTrace();
}
try {
ftpClient.login("xxxxx","xxxxxx");
} catch (IOException e2) {
e2.printStackTrace();
}
try {
ftpClient.ascii();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
ftpClient.cd("xxxx/log");
} catch (IOException e3) {
e3.printStackTrace();
}
InputStream in = null;
try {
in = ftpClient.list();
} catch (IOException e4) {
e4.printStackTrace();
}
int x = 0;
try {
x = in.read();
} catch (IOException e5) {
e5.printStackTrace();
}
while(x!=-1){
System.out.print((char)x);
try {
x = in.read();
} catch (IOException e6) {
e6.printStackTrace();
}
}
// System.out.println(ftpClient.list().toString());
String str = ftpClient.getResponseString();
System.out.println(str);
System.out.println("finish");
try {
url = new URL("ftp://xxx.xxx.xxx.x/xxxx/log/xxxxx.log");
} catch (MalformedURLException e6) {
e6.printStackTrace();
}
try {
ftpConn = (FtpURLConnection) url.openConnection();
} catch (IOException e9) {
e9.printStackTrace();
}
try {
InputStream reader = ftpConn.getInputStream();
} catch (IOException e7) {
e7.printStackTrace();
}
} public static void main(String[] args){
new FtpTest();
}
}
while(true){
String[] fn = f.list(); //获取所有子File对象
File tmp = null;
for(int i=0;i<fn.length();i++){
tmp = new File(fn[i])
if(tmp.isDirectory()){
继续朝下走两步
}else{
是文件了..入库入库,查查看以前有没有
if(o,new.file 新文件){
新来的,整吧....
}
}
}
//扫完了...太累了,改休息一下了
try{
Thread.sleep(1000*60); //让俺睡一分钟吧..整的累了
}catch(Exception e){}
}