如何使用Java将多个Csv文件从一个文件夹移动到另一个文件夹 [英] How Do I Move Multiple Csv Files From One Folder Into Another Folder Using Java

查看:86
本文介绍了如何使用Java将多个Csv文件从一个文件夹移动到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好程序员,我有一个文件夹,其中有一堆csv文件,我需要帮助将一些具有正确文件名的csv文件移动到一个名为correct的文件夹中,并保留错误的文件在同一个文件夹中注明名称,请注意两个文件都有相同的文件扩展名(.csv),例如你有一个名为fruits的文件夹,在fruits文件夹中你有文件,例如apples.csv和oranges.csv以及bananas。 csv,但你现在想要将所有带有apples.csv的文件移动到另一个名为new的文件夹中,这个移动必须始终自动完成,所以我认为某种循环对于连续/自动移动非常有用。



请我真的需要你们帮助我在java中找到这个代码我能得到的任何帮助都将非常感激。

Hello programmers,i have a folder that has a bunch of csv files in it,i need help with moving some of the csv files that have the correct name of a file into a folder called correct and leaving the files with the wrong name in the same folder,note that both files have the same file extension which is (.csv)for example you have a folder called fruits, and inside the fruits folder you have files such as apples.csv and oranges.csv and bananas.csv,but you now want to move all the files with apples.csv into another folder called new, and this move has to be done automatically at all times,so am thinking some kind of loop will be great for the continous/automatic move.

please i really need you guys to help me figure this code out in java any help i can get will be greatly appreciated.

推荐答案

请参阅 http://docs.oracle.com/javase/tutorial /本质/ IO /移动。 html [ ^ ]。


package com.sparity;

import java.io.File;
import java.io.FileNotFoundException;

public class MovingFilesFromOneFolderToAnotherFolder {
    public static void main(String[] args) throws FileNotFoundException {
        File file=new File(File.separator+"home"+File.separator+"patnaidu"+File.separator+"Documents"+File.separator+"materials"+File.separator+"gwt"+File.separator+"Untitled Folder");
        File[] fileNames=file.listFiles();
        System.out.println(fileNames.length);
        System.out.println(file.isDirectory());
        for(int i=0;i<fileNames.length;i++){
            fileNames[i].renameTo(new File(File.separator+"home"+File.separator+"patnaidu"+File.separator+"Documents"+File.separator+"materials"+File.separator+"gwt"+File.separator+"Untitled Folder 2"+File.separator+fileNames[i].getName()));
        }
    }
}







我认为这段代码会帮助你!




I Think This Code Will Help You!


这篇关于如何使用Java将多个Csv文件从一个文件夹移动到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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