Java Read File to String - HowToDoInJava

PHOTO EMBED

Sun Nov 07 2021 17:09:29 GMT+0000 (UTC)

Saved by @Adam101 #java #r/w #file

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

public class WriteToFile
{
	public static void main(String[] args) throws IOException
	{
		Path fileName = Path.of("demo.txt");
	    String content  = "hello world !!";
	    Files.writeString(fileName, content);

	    String actual = Files.readString(fileName);
	    System.out.println(actual);
	}
}
content_copyCOPY

https://howtodoinjava.com/java/io/java-read-file-to-string-examples/