Quantcast
Channel: How do I create a Java string from the contents of a file? - Stack Overflow
Viewing all articles
Browse latest Browse all 36

Answer by Saikat for How do I create a Java string from the contents of a file?

$
0
0

Using JDK 8 or above:

no external libraries used

You can create a new String object from the file content (Using classes from java.nio.file package):

public String readStringFromFile(String filePath) throws IOException {    String fileContent = new String(Files.readAllBytes(Paths.get(filePath)));    return fileContent;}

Viewing all articles
Browse latest Browse all 36

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>