简体   繁体   English

如何使用Java移动仅zip文件?

[英]How to move only zip file using java?

i want to move only zip file from one folder to another folder everyday. 我想每天仅将zip文件从一个文件夹移动到另一个文件夹。 Here is found a simple code from Developperzone website but it only copies a known txt file. 在Developperzone网站上可以找到一个简单的代码,但它仅复制一个已知的txt文件。

I want to use something like *.zip 我想使用* .zip之类的东西

Thank you 谢谢

import java.io.*;
public class CopyFile
  {
  public static void main(String args[]) throws Exception
    {
    BufferedReader br = new BufferedReader(
                        new FileReader("line.txt"));
    BufferedWriter bw = new BufferedWriter(
                        new FileWriter("linenum.txt"));
    String s, space="  ";
    int num=0;
    while (br.ready())
      {
      s=br.readLine();
      num++;
      bw.write(String.valueOf(num));
      bw.write(space);
      bw.write(s);
      bw.newLine();
      }
    bw.close();
    }
  }

Use java.io.File and its methods to get the list of .zip files and move them (Tutorial - Moving a File or Directory ). 使用java.io.File及其方法获取.zip文件列表并将其移动(教程- 移动文件或目录 )。

import static java.nio.file.StandardCopyOption.*;
...
Files.move(source, target, REPLACE_EXISTING); 

Do you mean some like this in linux? 您是说在Linux中这样的意思吗?

mv *.zip dest-dir

Why do you want to do this in Java? 为什么要用Java做到这一点?

I assume you want to move rather than copy? 我假设您想移动而不是复制?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM