I needed to read a whole bunch of files recently and instead of just grabbing my old FileUtils.java that I and probably most developers have and then copy from project to project, I decided to have quick look at how else to do it...
Yes, I know there is Commons IO and Google IO, why would I even bother? They probably do it better, but I wanted to check out the NIO jdk classes and play with lambdas aswell.. and to be honest, I think this actually ended up being a very neat bit of code.
So I had a specific use case:
I wanted to read all the source files from a whole directory tree, line by line.
What this code does, it uses Files.walk to recursively get all the paths from the starting point, it creates a stream, which I then filter to only files that end with the required extension. For each of those files, I use Files.lines to create a stream of Strings, one per line. I trim that, filter out the empty ones and add them to the return collection.
All very concise thanks to the new constructs.
Monday, May 26, 2014
Subscribe to:
Post Comments (Atom)
Popular Posts
-
I have recently been slacking on content on my blog, between long stressful hours at work and to the wonderful toy that is an iPhone, I have...
-
I make no claim to be a "computer scientist" or a software "engineer", those titles alone can spark some debate, I regar...
-
I saw an article (well more of a rant) the other day, by Rob Williams Brain Drain in enterprise Dev . I have to say, I do agree with some o...
-
This series of posts will be about me getting to grips with JBoss Drools . The reasoning behind it is: SAP bought out my company's curre...
-
I recently finished 97 Things every programmer should know . Well to be completely honest I did skim over a couple of the 97, but all and al...
This is one such interesting and useful article that i have ever read. The way you have structured the content is so realistic and meaningful. Thank you so much for sharing this in here. Keep up this good work and I'm expecting more contents like this from you in future.
ReplyDeleteHadoop Training Chennai | Hadoop Training in Chennai | big data Training in Chennai
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training India . Nowadays Java has tons of job opportunities on various vertical industry.
DeleteThe effectiveness of IEEE Project Domains depends very much on the situation in which they are applied. In order to further improve IEEE Final Year Project Domains practices we need to explicitly describe and utilise our knowledge about software domains of software engineering Final Year Project Domains for CSE technologies. This paper suggests a modelling formalism for supporting systematic reuse of software engineering technologies during planning of software projects and improvement programmes in Final Year Project Centers in Chennai.
DeleteSpring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai
The best thing is that your blog really informative thanks for your great information!
ReplyDeleteerp in chennai
There are many companies that offer professional solutions to the striving business people and help them succeed in their online endeavors. Further, it is platform dependent and runs anywhere, anytime once deployed.
ReplyDeletelearn web design
have got some important suggestions from it. You post explain everything in detail and it was very interesting to read. Thank you.
ReplyDeleteWeb designing course in chennai
I would like to say thank you for the amazing details and concepts you are sharing in this.
ReplyDeleteWebseiten Gestaltung Lüdenscheid
Interesting post! This is really helpful for me. I like it! Thanks for sharing!
ReplyDeletemicrosoft office online
Thanks, your article helped me to solve my old problem, cause transient variable java https://explainjava.com/java-transient/ was always one of the most complicated theme for understanding for me. But then I started to read your site and situation quickly turned and the situation quickly turned into a better one.
ReplyDeleteInteresting post! This is really helpful for me. I like it! Thanks for sharing!
ReplyDeleteonline marketing lüdenscheid
There are so many useful information in your post, I like it all the time. And I want to share this boost app ranking with you, you can take a look. This is very useful.
ReplyDeletePretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
ReplyDeleteEmbedded system training in Chennai
Embedded system Course in Chennai
The website is looking bit flashy and it catches the visitors eyes. A design is pretty simple .
ReplyDeleteonline marketing lüdenscheid
I enjoy what you guys are usually up too. This sort of clever work and coverage! Keep up the wonderful works guys I’ve added you guys to my blog roll..,
ReplyDeletewhite label website builder
mobile website builder
Nice article, I loved it.
ReplyDeletepersonalrekrutierung
The website is looking bit flashy and it catches the visitors eyes. A design is pretty simple .
ReplyDeleteregionale stellenbörse
really good
ReplyDeletejobbörse südwestfalen
This news is crucial for all of us.
ReplyDeleteI enjoyed to visiting your blog. You have done a really nice job.
ReplyDeleteReally wonderful blog! Thanks for taking your valuable time to share this with us. Keep us updated with more such blogs.
ReplyDeleteWordPress Training in Chennai
WordPress Course in Chennai
JavaScript Training in Chennai
JavaScript Course in Chennai
C C++ Training in Chennai
C Training in Chennai
WordPress Training in Porur
WordPress Training in Adyar
Python Course in Bangalore with Placement Assistance. Get trained by Industry Experts with Real Time Projects. Learn Python from basics to advanced Concepts. Please visit our website to know more information.
ReplyDeletehttps://onlineidealab.com/python-training-in-bangalore/
Đại lý vé máy bay Aivivu, tham khảo
ReplyDeletevé máy bay đi Mỹ giá bao nhiêu
giá vé máy bay tết 2021
giá vé máy bay đi toronto Canada
giá vé máy bay đi Pháp
ve may bay di Anh gia re
vé máy bay giá rẻ 99k
combo khách sạn đà nẵng
combo du lịch nha trang
làm visa trung quốc giá rẻ tphcm
cách ly khách sạn trọn gói