Thursday, February 22, 2018

Java File to String in one Line


This is the shortest version of how to read a file and convert it to String in Java:

String myFile = "";
try{
    myFile = new String(Files.readAllBytes(Paths.get(myFile.txt)) );
}
catch (IOException e)
{
    e.printStackTrace();
}

2 comments:

  1. Very good post.
    All the ways that you suggested for find a new post was very good.
    Keep doing posting and thanks for sharing.11:38 AM 9/10/2018
    mobile repairing course in hyderabad

    ReplyDelete