简体   繁体   中英

Getting an array of files into a java class

I'm writing a program that takes in two types of files and outputs a combination of their contents. The details of this part are unimportant. All I need to know is how to add the files of two directories into two separate arrays so that I can iterate through all of them and perform my work on them more simply than loading each file individually. The files have the same names but different extensions. So by loading the files into arrays, since they are in the same order, I will be able to iterate through them and get my desired information. Any suggestions?

edit: here is the code

import java.io.File;


public class FileImporter 
{
    File[] metricsFiles;
    File[] logFiles;

    public FileImporter()
    {
        metricsFiles = new File(System.getProperty("/Users/aarongrove/Desktop/Code Generator data/metrics")).listFiles();
    }
    public void printFiles()
    {
        for (int i=0;i < metricsFiles.length;i++) 
        {
            System.out.println(metricsFiles[i]);
        }
    }
}

从Apache commons中检查DirectoryWalker ,它使您可以遍历目录层次结构。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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