带有短信警告的文件监视 [英] file watch with sms warning

查看:61
本文介绍了带有短信警告的文件监视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发一个监视文件目录的系统,例如C:/我的文件,如果此目录将进行某些更改或添加了其他文件...将通过SMS合并自动警报...

需要开发此代码,以便包含SMS发送(在命令中包含)...





代码以监视文件列表中具有文件名的文件夹中的新文件:-2008年4月4日,上午08:26

-------------------------------------------------- ------------------------------

导入java.io.File;

导入java.util.ArrayList;
导入java.util.List;

公共类FileTest
实现Runnable {
静态int fileCount;
静态线程t;
静态File [] existingFiles;
static int counterCheck = 0;
清单清单;

公共静态void main(String [] args){
FileTest测试=新的FileTest();

t =新线程(测试);
t.start();
}

public void run(){
int currentFilecount = 0;
File f = new File("test");
布尔状态= f.isDirectory();
File [] currentFiles = null;

if(状态){
currentFilecount = f.listFiles().length;

如果(counterCheck == 0){
existingFiles = f.listFiles();
counterCheck ++;
}
} else {
f.mkdir();
}

if(fileCount == currentFilecount){
System.out.println(没有新文件");
} else {
System.out.println(新文件数:"
+(currentFilecount-fileCount));
currentFiles = f.listFiles();
this.list = compaireArray(existingFiles,currentFiles);
fileCount = currentFilecount;
existingFiles = currentFiles;
}

尝试{
t.sleep(7000);
} catch(InterruptedException e){
//TODO自动生成的捕获块
e.printStackTrace();
}

t.run();
}

/**
*比较两个数组,并在新文件数组中返回新文件!
* @param existingFiles2
* @param currentFiles
* @return
*/
私有列表compaireArray(File [] existingFiles2,File [] currentFiles){
列表列表= new ArrayList();
int计数器= 0;

for(int i = 0; i< currentFiles.length; i ++){
for(int j = i; j< existingFiles2.length; j ++){
如果(currentFiles [i] .getName().equals(
existingFiles2 [j] .getName())){
休息;
} else {
list.add(currentFiles [j] .getName());
counter ++;
}
}
}

if(list!= null){
for(int i = 0; i< list.size(); i ++){
System.out.println((String)list.get(i));
}
}

返回列表;
}
/**
*返回新添加的文件
* @return
*/
公共列表getNewFile(){
返回this.list;
}

}

DEVELOP A SYSTEM THAT MONITORS A FILE DIRECTORY LIKE C :/ MY DOCUMENTS IF THIS DIRECTORY WILL HAVE SOME CHANGES OR ADDITIONAL FILES ARE ADDED... AN AUTOMATIC ALERT WILL BE INCORPORATED VIA A SMS...

NEED THIS CODE TO BE DEVELOPED SO THAT SMS SENDING( INCORPORATE AT COMMANDS WITH IT) WILL BE INCLUDED...





code to monitor new files in folder with file name in the arraylist: - 04-04-2008, 08:26 AM

--------------------------------------------------------------------------------

import java.io.File;

import java.util.ArrayList;
import java.util.List;

public class FileTest
implements Runnable {
static int fileCount;
static Thread t;
static File[] existingFiles;
static int counterCheck = 0;
List list;

public static void main(String[] args) {
FileTest test = new FileTest();

t = new Thread(test);
t.start();
}

public void run() {
int currentFilecount = 0;
File f = new File("test");
boolean status = f.isDirectory();
File[] currentFiles = null;

if (status) {
currentFilecount = f.listFiles().length;

if (counterCheck == 0) {
existingFiles = f.listFiles();
counterCheck++;
}
} else {
f.mkdir();
}

if (fileCount == currentFilecount) {
System.out.println("No new file");
} else {
System.out.println("No. of new files : "
+ (currentFilecount - fileCount));
currentFiles = f.listFiles();
this.list = compaireArray(existingFiles, currentFiles);
fileCount = currentFilecount;
existingFiles = currentFiles;
}

try {
t.sleep(7000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

t.run();
}

/**
* compares two array and returns the new files in a new file array !
* @param existingFiles2
* @param currentFiles
* @return
*/
private List compaireArray(File[] existingFiles2, File[] currentFiles) {
List list = new ArrayList();
int counter = 0;

for (int i = 0; i < currentFiles.length; i++) {
for (int j = i; j < existingFiles2.length; j++) {
if (currentFiles[i].getName().equals(
existingFiles2[j].getName())) {
break;
} else {
list.add(currentFiles[j].getName());
counter++;
}
}
}

if (list != null) {
for (int i = 0; i < list.size(); i++) {
System.out.println((String) list.get(i));
}
}

return list;
}
/**
* returns the newly added files
* @return
*/
public List getNewFile() {
return this.list;
}

}

推荐答案

这似乎是您张贴作业的文本,然后尝试至少回答其中的一部分.我在这里看不到任何问题,尽管我知道您之前已经问过一次并得到了答复.也许您不应该一遍又一遍地问同样的事情,而是编辑帖子?也许您应该尝试一下上次问到的内容?
This looks like you posted the text of an assignment, and then your attempt to answer at least part of it. I don''t see a question here, although I know you''ve asked this once before, and been answered. Perhaps you should not ask the same thing over and over, but edit your post instead ? Perhaps you should try the stuff you were told last time you asked ?


这篇关于带有短信警告的文件监视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆