Results 1 to 5 of 5
  1. #1
    litlmike is offline Member
    Join Date
    May 2016
    Posts
    6
    Rep Power
    0

    Default How do I find file of types

    I would like to turn this code into only returning file types ".xls" and ".xlsx". Can you help?

    Thanks!

    Java Code:
    Files.walk(Paths.get(".")).forEach(filePath -> {
    		    if (Files.isRegularFile(filePath)) {
    		        System.out.println(filePath);
    		    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: How do I find file of types

    You can use the endsWith() method and check for each of those extensions.
    If you declare a List<Path> before the walk call you can then add each one that matches to that List.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    litlmike is offline Member
    Join Date
    May 2016
    Posts
    6
    Rep Power
    0

    Default Re: How do I find file of types

    Thanks, where do I put the endsWith? After what call? Sorry, I'm new

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: How do I find file of types

    Use the toString method on your Path (filePath is a Path) and then use endsWith on the returned String.

    Java Code:
    Path somePath ...
    if (somePath.toString().endsWith(".some-extension")) {
        // do whatever with the filePath (add to a List maybe?)
    }
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    litlmike is offline Member
    Join Date
    May 2016
    Posts
    6
    Rep Power
    0

Similar Threads

  1. Jfilechooser removing all file types
    By counterfox in forum New To Java
    Replies: 2
    Last Post: 02-15-2011, 10:55 AM
  2. Replies: 5
    Last Post: 01-27-2010, 09:14 PM
  3. Open type (Ctrl-Shift-T) does not find types
    By Zhenya_Merom in forum Eclipse
    Replies: 2
    Last Post: 11-04-2009, 10:15 AM
  4. Replies: 7
    Last Post: 08-28-2009, 08:23 AM
  5. Replies: 0
    Last Post: 04-17-2008, 07:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •