package org.kodejava.commons.io;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class WriteToFileExample {
public static void main(String[] args) {
try {
// Here we'll write our data into a file called
// output.txt, this is the output.
File file = new File("output.txt");
// We'll write the string below into the file
String data = "Learn Java by Examples";
// To write a file called the writeStringToFile
// method which require you to pass the file and
// the data to be written.
FileUtils.writeStringToFile(file, data, "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Maven Dependencies
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
Latest posts by Wayan (see all)
- How do I build simple search page using ZK and Spring Boot? - March 8, 2023
- How do I calculate days between two dates excluding weekends and holidays? - January 12, 2023
- How do I discover the quarter of a given date? - January 11, 2023