java.io

Class FileWriter

Implemented Interfaces:
Appendable, Closeable, Flushable

public class FileWriter
extends OutputStreamWriter

Convenience class for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.

Whether or not a file is available or may be created depends upon the underlying platform. Some platforms, in particular, allow a file to be opened for writing by only one FileWriter (or other file-writing object) at a time. In such situations the constructors in this class will fail if the file involved is already open.

FileWriter is meant for writing streams of characters. For writing streams of raw bytes, consider using a FileOutputStream.

Since:
JDK1.1
See Also:
OutputStreamWriter, FileOutputStream

Field Summary

Fields inherited from class java.io.Writer

lock

Constructor Summary

FileWriter(File file)
Constructs a FileWriter object given a File object.
FileWriter(File file, boolean append)
Constructs a FileWriter object given a File object.
FileWriter(FileDescriptor fd)
Constructs a FileWriter object associated with a file descriptor.
FileWriter(String fileName)
Constructs a FileWriter object given a file name.
FileWriter(String fileName, boolean append)
Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.

Method Summary

Methods inherited from class java.io.OutputStreamWriter

close, flush, getEncoding, write, write, write

Methods inherited from class java.io.Writer

append, append, append, close, flush, write, write, write, write, write

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

FileWriter

public FileWriter(File file)
            throws IOException
Constructs a FileWriter object given a File object.
Parameters:
file - a File object to write to.
Throws:
IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
Usages and Demos :

View More Examples of FileWriter(File file)
   1: 
   2:             PrintWriter pw = new PrintWriter(new FileWriter("../fooFactory.ior"));
   3:             pw.println(orb.object_to_string(reference));
   4:             pw.close(); 
   5:             poaMgr.activate();

View Full Code Here
   1:       long start = System.currentTimeMillis();
   2:       PrintWriter out = new PrintWriter(new FileWriter("CharWriterDemo.tmp"));
   3:       for (int i = 0; i < args.length; i++) {
   4:          out.println(args[i]);
   5:       }

View Full Code Here
   1:       long start = System.currentTimeMillis();
   2:       BufferedWriter out = new BufferedWriter(new FileWriter("CharWriterDemo.tmp"));
   3:       for (int i = 0; i < args.length; i++) {
   4:          out.write(args[i]);
   5:          out.newLine();

View Full Code Here
   1:       long start = System.currentTimeMillis();
   2:       PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("CharWriterDemo.tmp")), true);
   3:       for (int i = 0; i < args.length; i++) {
   4:          out.println(args[i]);
   5:       }

View Full Code Here
   1:       File f = new File("/tmp/000001");
   2:       FileWriter fw = new FileWriter(f.getPath());
   3: 
   4:         ...
   5: 
   6:       fw = new FileWriter(f.getPath(), true);
   7:       buf = new char[s2.length()];
   8:         ...
   9:     {
  10:       FileWriter fw = new FileWriter("/etc/newtempfile");
  11:       System.out.println("FAILED: Permission Denied Test");

View Full Code Here

FileWriter

public FileWriter(File file,
                  boolean append)
            throws IOException
Constructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.
Parameters:
file - a File object to write to
append - if true, then bytes will be written to the end of the file rather than the beginning
Throws:
IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
Since:
1.4
Usages and Demos :

View More Examples of FileWriter(File file,boolean append)
   1:         try{    
   2:         PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("c:\\log.txt",true)));
   3:         out.println("Time:"+new java.util.Date().toLocaleString());
   4:         ...
   5:          {
   6:              PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("c:\\log.txt",true)));
   7:           out.println("Time:"+new java.util.Date().toLocaleString());
   8:           out.println("from :"+cl);
   9:           out.println("Message:"+e.getMessage());

View Full Code Here
   1:     {
   2:         FileWriter fw = new FileWriter(SigPathConstants.DBSTATUSFILE, true);
   3:         status = statusPrefix + status + "\n";
   4:         ...
   5:     {
   6:         FileWriter fw = new FileWriter(SigPathConstants.DBSTATUSFILE, true);
   7:         msg = msgPrefix + msg + "\n";
   8:         fw.write(msg);
   9:         fw.close();

View Full Code Here
   1:             File outFile = new File(SigPathConstants.TIMERLOG);
   2:             FileWriter fw = new FileWriter(SigPathConstants.TIMERLOG, true);
   3:             out+=getTimeElapsed()+"\n";
   4:             fw.write(out);
   5:             fw.close();

View Full Code Here
   1:       FileWriter out =
   2:             new FileWriter("c:\\temp\\mailmonitor.log", true);
   3:       String datum = new java.util.Date().toString();
   4:       out.close();
   5:     }

View Full Code Here
   1:             try {
   2:                 FileWriter  fw   = new FileWriter( "axis.log", true );
   3:                 PrintWriter pw   = new PrintWriter( fw );
   4:         ...
   5:         try {
   6:             FileWriter  fw   = new FileWriter( "axis.log", true );
   7:             PrintWriter pw   = new PrintWriter( fw );
   8:             pw.println( "=====================" );
   9:             pw.println( "= " + Messages.getMessage("fault00") );

View Full Code Here

FileWriter

public FileWriter(FileDescriptor fd)
Constructs a FileWriter object associated with a file descriptor.
Parameters:
fd - FileDescriptor object to write to.
Usages and Demos :

View More Examples of FileWriter(FileDescriptor fd)
   1: 
   2:             PrintWriter pw = new PrintWriter(new FileWriter("../fooFactory.ior"));
   3:             pw.println(orb.object_to_string(reference));
   4:             pw.close(); 
   5:             poaMgr.activate();

View Full Code Here
   1:       long start = System.currentTimeMillis();
   2:       PrintWriter out = new PrintWriter(new FileWriter("CharWriterDemo.tmp"));
   3:       for (int i = 0; i < args.length; i++) {
   4:          out.println(args[i]);
   5:       }

View Full Code Here
   1:       long start = System.currentTimeMillis();
   2:       BufferedWriter out = new BufferedWriter(new FileWriter("CharWriterDemo.tmp"));
   3:       for (int i = 0; i < args.length; i++) {
   4:          out.write(args[i]);
   5:          out.newLine();

View Full Code Here
   1:       long start = System.currentTimeMillis();
   2:       PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("CharWriterDemo.tmp")), true);
   3:       for (int i = 0; i < args.length; i++) {
   4:          out.println(args[i]);
   5:       }

View Full Code Here
   1:       File f = new File("/tmp/000001");
   2:       FileWriter fw = new FileWriter(f.getPath());
   3: 
   4:         ...
   5: 
   6:       fw = new FileWriter(f.getPath(), true);
   7:       buf = new char[s2.length()];
   8:         ...
   9:     {
  10:       FileWriter fw = new FileWriter("/etc/newtempfile");
  11:       System.out.println("FAILED: Permission Denied Test");

View Full Code Here

FileWriter

public FileWriter(String fileName)
            throws IOException
Constructs a FileWriter object given a file name.
Parameters:
fileName - String The system-dependent filename.
Throws:
IOException - if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
Usages and Demos :

View More Examples of FileWriter(String fileName)
   1: 
   2:             PrintWriter pw = new PrintWriter(new FileWriter("../fooFactory.ior"));
   3:             pw.println(orb.object_to_string(reference));
   4:             pw.close(); 
   5:             poaMgr.activate();

View Full Code Here
   1:       long start = System.currentTimeMillis();
   2:       PrintWriter out = new PrintWriter(new FileWriter("CharWriterDemo.tmp"));
   3:       for (int i = 0; i < args.length; i++) {
   4:          out.println(args[i]);
   5:       }

View Full Code Here
   1:       long start = System.currentTimeMillis();
   2:       BufferedWriter out = new BufferedWriter(new FileWriter("CharWriterDemo.tmp"));
   3:       for (int i = 0; i < args.length; i++) {
   4:          out.write(args[i]);
   5:          out.newLine();

View Full Code Here
   1:       long start = System.currentTimeMillis();
   2:       PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("CharWriterDemo.tmp")), true);
   3:       for (int i = 0; i < args.length; i++) {
   4:          out.println(args[i]);
   5:       }

View Full Code Here
   1:       File f = new File("/tmp/000001");
   2:       FileWriter fw = new FileWriter(f.getPath());
   3: 
   4:         ...
   5: 
   6:       fw = new FileWriter(f.getPath(), true);
   7:       buf = new char[s2.length()];
   8:         ...
   9:     {
  10:       FileWriter fw = new FileWriter("/etc/newtempfile");
  11:       System.out.println("FAILED: Permission Denied Test");

View Full Code Here

FileWriter

public FileWriter(String fileName,
                  boolean append)
            throws IOException
Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.
Parameters:
fileName - String The system-dependent filename.
append - boolean if true, then data will be written to the end of the file rather than the beginning.
Throws:
IOException - if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
Usages and Demos :

View More Examples of FileWriter(String fileName,boolean append)
   1:         try{    
   2:         PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("c:\\log.txt",true)));
   3:         out.println("Time:"+new java.util.Date().toLocaleString());
   4:         ...
   5:          {
   6:              PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("c:\\log.txt",true)));
   7:           out.println("Time:"+new java.util.Date().toLocaleString());
   8:           out.println("from :"+cl);
   9:           out.println("Message:"+e.getMessage());

View Full Code Here
   1:     {
   2:         FileWriter fw = new FileWriter(SigPathConstants.DBSTATUSFILE, true);
   3:         status = statusPrefix + status + "\n";
   4:         ...
   5:     {
   6:         FileWriter fw = new FileWriter(SigPathConstants.DBSTATUSFILE, true);
   7:         msg = msgPrefix + msg + "\n";
   8:         fw.write(msg);
   9:         fw.close();

View Full Code Here
   1:             File outFile = new File(SigPathConstants.TIMERLOG);
   2:             FileWriter fw = new FileWriter(SigPathConstants.TIMERLOG, true);
   3:             out+=getTimeElapsed()+"\n";
   4:             fw.write(out);
   5:             fw.close();

View Full Code Here
   1:       FileWriter out =
   2:             new FileWriter("c:\\temp\\mailmonitor.log", true);
   3:       String datum = new java.util.Date().toString();
   4:       out.close();
   5:     }

View Full Code Here
   1:             try {
   2:                 FileWriter  fw   = new FileWriter( "axis.log", true );
   3:                 PrintWriter pw   = new PrintWriter( fw );
   4:         ...
   5:         try {
   6:             FileWriter  fw   = new FileWriter( "axis.log", true );
   7:             PrintWriter pw   = new PrintWriter( fw );
   8:             pw.println( "=====================" );
   9:             pw.println( "= " + Messages.getMessage("fault00") );

View Full Code Here