Google | Telephonic | Reject
Anonymous User
1234

problem to read files in a computer system. Given a directory find all the files and read them. What happens if it was 2TB of data would my solution be efficient or not.

Did something like this:

private static void listFiles(String path)
    {
        File folder = new File(path);
 
        File[] files = folder.listFiles();
 
        for (File file : files)
        {
            if (file.isFile())
            {
                System.out.println(file.getName());
            }
            else if (file.isDirectory())
            {
                listFiles(file.getAbsolutePath());
            }
        }
    }

Follow up : What happens if it was 2TB of data. I said we could read the files in chunk and provide a buffer size but I think he was saying more in terms of recursion . Is there any other efficient approach we could do? I was also thinking of iterative solution using stack.

Comments (2)