Reading File Content In Java 8

This is a short post on how to read the content of a File into a String in Java 8. I'm writing it here just to help myself remember it, and maybe help others at the same time.

In Java 8, reading of the File into a String variable is simplified and can be done using the following lines of code

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class StreamsFiles {

 public static void main(String[] args) throws IOException {
     //read contents of file in 1 single line, isn't that great? 
     String content = new String(Files.readAllBytes(Paths.get("L:/file.txt")));
     System.out.println(content);
}


Now, you know how simple it is to read a file in Java 8, why not start using it?

See you around
Share on Google+

About Sujit Horakeri

Sujit Horakeri is a game freak just like any other next door guy you would come across. He is a Web Developer by Profession, Game Developer by Choice.
Connect with him on:
    Blogger
    Facebook

11 comments:

  1. Learning new technolgoy would help oneself at hard part of their career. And staying updated is the only way to survive in current position. Your content tells the same. Thanks for sharing this information in here. Keep blogging like this.

    JAVA J2EE Training Institutes in Chennai | JAVA Training | JAVA Course in Chennai | Hadoop training in chennai

    ReplyDelete
  2. Responsive desing can yield a very good revenue to a business. It has been discovered since the usage of multiple devices increase. The content furnished above too tells the same. Thanks for sharing this information in here. Please keep bloging content like this.

    Web designing course in chennai | Web design training | PHP Training in Chennai

    ReplyDelete
  3. To keep ourselves up to date with the current trend is not an easy task in IT. But we can, through quality and worth able content like this. Thanks for sharing this web page. Please write more articles like this in future.
    PHP training in Chennai | PHP course in Chennai

    ReplyDelete
  4. To keep ourselves up to date with the current trend is not an easy task in IT. But we can, through quality and worth able content like this. Thanks for sharing this web page. Please write more articles like this in future.
    PHP training in Chennai | PHP course in Chennai

    ReplyDelete
  5. These all are notable facts… I stick with responsive website design for my business. With the mobile marketing is at its peak stage, having website that goes comfy on all devices will help your business. You can check my website for more details on the importance of responsive website design. PHP Training Institute in Chennai | Best PHP training in Chennai | PHP Training Institute in Chennai

    ReplyDelete
  6. Updating with the latest technology and implementing it is the only way to survive in our niche. Thanks for making me this article. You have done a great job by sharing this content in here. Keep writing article like this.
    SAS Training in Chennai | SAS Course in Chennai

    ReplyDelete
  7. Hi to every one, the contents present at this site are
    actually remarkable for people experience, well, keep up the good work fellows
    Best institute chennai

    ReplyDelete
  8. Good post..Keep Sharing.! I'm working in brave technologies private limited. We are the leading ERP software development company in chennai.

    ReplyDelete