要求是每隔一段时间(1分钟)将指定文件移到指定目录下!现已经有程序对该目录下的文件处理。
该如何实现?
该如何实现?
解决方案 »
- 用java 编写程序求最大连续递增的有序子串(求解)
- 这个是因为变量没配置正确吗?
- java连接Access数据库,请问那里错了????
- cannot find win.com!!!高手救命!!!!
- RandomAccessFile的readUTF()方法无法读取数据报表.
- 定义一个a类, a类是基类,b类是a类的子类,用b创建的对象是a类还是b类的实例?
- 求助,请帮我看看哪出了问题
- java的输入输出问题-我的程序为什么错?
- 求教:请评价<最新Java 2核心技术卷I:原理(原书第5版) >这本书如何?
- 请问如何查看和设置tomcat的编码方式?
- 以空格结束输入字符串
- jdbc.drivers属性设定
java中文件拷贝用流的方式
如果是同一机器上的文件拷贝可以用
File.rename()方法
public static void main(String[] args) throws IOException {
//set timer
Timer timer = new Timer();
long timeIterval = Long.valueOf(args[2]).longValue();
//System.out.println("test iterval" + timeIterval);
//timeInterval = args[3];
if (args[1] != null && args[1].length() != 0) {
if (args[0] != null && args[0].length() != 0) {
File inputFile = new File(args[0]);
if (inputFile.exists()) {
RunTimer runTimer = new RunTimer(args[0], args[1]);
timer.scheduleAtFixedRate(runTimer, 500, timeIterval);
} else {
System.out.println("file not existed");
}
}
}
}
}class RunTimer extends TimerTask {
int i = 0; String inputFileName = ""; String outputFileName = ""; /**
* @param string
*/
public RunTimer(String inputDir, String outPutDir) {
inputFileName = inputDir;
outputFileName = outPutDir;
// TODO Auto-generated constructor stub
} public void run() {
FileInputStream fin = null;
try {
//fin = new FileInputStream("E:\\test.txt");
fin = new FileInputStream(inputFileName);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
File fcopy = new File(outputFileName);
try {
if (fcopy.exists()) {
System.out.println("file already existed");
} else {
fcopy.createNewFile();
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
FileOutputStream fout = null;
try {
fout = new FileOutputStream(fcopy);
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
int stae;
try {
while ((stae = fin.read()) != -1) {
fout.write(stae);
}
fout.close();
} catch (IOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
System.out.println("" + (i++));
}
}