用JAVA写一个程序每隔一秒扫描c:\Mailboxes\in下所有EML形式文件
发布网友
发布时间:2022-05-12 09:07
我来回答
共1个回答
热心网友
时间:2024-02-20 18:49
public static void main(String[] args) {
// TODO Auto-generated method stub
int j = 0;
while(j<5) {
File f = new File("c:/Mailboxes/in/");
File[] fArray = f.listFiles();
for(int i=0; i<fArray.length; i++) {
if(fArray[i].getName().matches("[\\w]*.EML$")) {
System.out.println(fArray[i].getName());
try {
FileInputStream is = new FileInputStream(fArray[i]);
byte[] b = new byte[(int)fArray[i].length()];
is.read(b);
FileOutputStream os = new FileOutputStream("c:/mail/" + fArray[i].getName());
os.write(b);
os.close();
is.close();
fArray[i].delete();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
j++;
}
}