How to write content from a String into File in Java?


I have a string that to be written into a File, How can i do that in Java?

1 Answer

7 years ago by

String contentTobeWritten = "This is the new content you will see in file";
Files.write(Paths.get("/path/to/file"), contentTobeWritten.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
7 years ago by Karthik Divi