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();
}

No comments:

Post a Comment