The following example demonstrates using the write() method to write content to a file:
/* author by w3cschool.cc Main.java */import java.io.*;public class Main { public static void main(String[] args) { try { BufferedWriter out = new BufferedWriter(new FileWriter("outfilename")); out.write("w3cschool菜鸟教程"); out.close(); System.out.println ("文件创建成功!"); } catch (IOException e) { } }}
The output result of running the above code is:
文件创建成功!
The current directory after successful creation The following will generate a file named outfilename and write the "w3cschool novice tutorial" string into the file.
The above is the Java example - the content written in the file. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!