logo image

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

2 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);
2 years ago by Megamind