package org.kodejava.example.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 Programming 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
<!-- http://repo1.maven.org/maven2/commons-io/commons-io/2.6/commons-io-2.6.jar -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
Latest posts by Wayan (see all)
- How do I create a generic class in Java? - January 1, 2021
- How do I convert java.util.TimeZone to java.time.ZoneId? - April 25, 2020
- How do I get a list of all TimeZones Ids using Java 8? - April 25, 2020