Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:54:21+00:00 2026-06-10T17:54:21+00:00

In Java 7 with the new I/O APIs, is there an easy way to

  • 0

In Java 7 with the new I/O APIs, is there an easy way to list a directory’s content by last modified date? Basically I only need to get the file the wasn’t modified for the longest time (sort by last modified ascending, take first filename).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:54:23+00:00Added an answer on June 10, 2026 at 5:54 pm

    There’s no real “easy way” to do it, but it is possible:

    List<Path> files = new ArrayList<>();
    try(DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
        for(Path p : stream) {
            files.add(p);
        }
    }
    
    Collections.sort(files, new Comparator<Path>() {
        public int compare(Path o1, Path o2) {
            try {
                return Files.getLastModifiedTime(o1).compareTo(Files.getLastModifiedTime(o2));
            } catch (IOException e) {
                // handle exception
            }
        }
    });
    

    This will sort the files soonest modified files last. DirectoryStreams do not iterate through subdirectories.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

java.util.Date date = new java.util.Date(); java.sql.Date today = new java.sql.Date(date.getTime()); //2012-03-23 java.sql.Time time =
SimpleDateFormat formatter = new SimpleDateFormat(ddMMyyyy_HHmmSS); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = Cust_Advice_
is there really no way to directly write formatted XML using javax.xml.stream.XMLStreamWriter (Java SE
I am new to programming, I was wondering if there is a way to
When creating a Socket in Java: new Socket(host, port); The Socket constructor will try
When creating a new Java project in IntelliJ IDEA, the following directories and files
I am used to Java and new to QT/C++, and I have some problems
When I start a new Java project in eclipse, the first popup screen allow
We are starting a new Java EE project and am looking for suggestions regarding
I am starting a new Java web project that will be worked on by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.