Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

FIle.list() for specific file types  RSS feed

 
Paul Peterson
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to use the list() method of the file class to create an array of only certain file types.  For example, say I wanted to search a given directory for files ending in .ser.  Or would I have to create the original array using the list command then create a new array searching for the correct file types?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37222
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Take a look at the version of the method that takes a parameter.
 
Paul Peterson
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found an example for filter filename and modified it to fit my application.  Obviously I missed something, probably something silly.  I am getting a null pointer exception.  This is what I am trying to use:

 
Paweł Baczyński
Bartender
Posts: 2054
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you set f to null at line 5.
Then you call a method on f on line 26.
That's the reason of NPE.

Please provide SSCCE when asking questions.
I was not able to run your code because it missed declarations of master, Order, deserializeOrders, orderFiles, etc...
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Peterson wrote:Obviously I missed something, probably something silly.  I am getting a null pointer exception.  This is what I am trying to use:



Well, you set the "f" reference variable to null, so, when you tried to deference it to call the listFiles() method, you will get a null pointer exception.

Henry
 
Paul Peterson
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I mentioned, I was following an example I found online.  And we know if it's on the internet it must be true...

This was the source I referenced...



A nudge in the correct direction is much appreciated.
 
Paweł Baczyński
Bartender
Posts: 2054
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please note line 14 of the "Internet code" and compare it with yours.
 
Paul Peterson
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, that cleared the error. 
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!