FileWriter class example

xiaoxiao2021-04-06  261

/ *

FileWriter Creates a Writer class that can write files. Its most commonly used constructor is as follows:

FileWriter (String FilePath)

FileWriter (String Filepath, Boolean Append)

Filewriter (File fileobj)

They can trigger ioException or securityException. Here, FILEPATH is a full path to the file, and fileobj is a File object that describes the file. If append is true, the output is attached to the file. The creation of the FileWriter class is not dependent on the file or not. Before creating a file, FileWrit is turned on when you create an object as an output. If you try to open a read-only file, it will trigger an ioException exception.

* /

// Demonstrate FileWriter.import java.io *;. Class FileWriterDemo {public static void main (String [] args) throws Exception {String source = "Now is the time for all good men / n" "to come to the aid Of their country / n " " and pay their due Taxes. "; char buffer [] = new char [Source.Length ()]; Source.GetChars (0, Source.Length (), Buffer, 0); FileWriter F0 = New FileWriter ("file1.txt"); for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-132311.html

New Post(0)