Read a file to a string in a single line of Java
23
Jun
Rarely in my career have I written significant amounts of Java, so when I do use it I’m always learning new things. I thought this unique way to use Scanner to read a text file into a string was great:
1 2 |
import java.util.Scanner; String contents = new Scanner(new File(fileName)).useDelimiter("\\Z").next(); |
Nice … Read More »