com.javaranch.common
Class TextFileOut

java.lang.Object
  |
  +--java.io.Writer
        |
        +--java.io.BufferedWriter
              |
              +--com.javaranch.common.TextFileOut

public final class TextFileOut
extends java.io.BufferedWriter

A convenience class for writing text files.

Example usage of TextFileOut:


 String[] s;

 // fill array with lovely prose

 TextFileOut f = new TextFileOut( "file.txt" );
 for( int i = 0 ; i < s.length ; i++ )
 {
     f.println( s[ i ] );
 }
 f.close();

    

- - - - - - - - - - - - - - - - -

Copyright (c) 1998-2004 Paul Wheaton

You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...

My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.

The original source can be found at JavaRanch

- - - - - - - - - - - - - - - - -

Author:
Paul Wheaton

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
TextFileOut(java.lang.String filename)
          Create a new TextFileOut object that will start writing at the beginning of the file.
TextFileOut(java.lang.String filename, boolean append)
          Same as the other constructor only this will open the file for appending.
 
Method Summary
 void print(java.lang.String s)
          Send a line of text to the file.
 void println()
          Send a newline to the file.
 void println(java.lang.String s)
          Send a line of text to the file with a trailing new line appropriate for the o/s.
 void writeLine(java.lang.String s)
          Send a line of text to the file with a trailing new line appropriate for the o/s.
 
Methods inherited from class java.io.BufferedWriter
close, flush, newLine, write, write, write
 
Methods inherited from class java.io.Writer
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextFileOut

public TextFileOut(java.lang.String filename)
            throws java.io.IOException
Create a new TextFileOut object that will start writing at the beginning of the file.


TextFileOut

public TextFileOut(java.lang.String filename,
                   boolean append)
            throws java.io.IOException
Same as the other constructor only this will open the file for appending.

Parameters:
filename - The name of the file to open.

append - Pass in "true" to append.

Method Detail

println

public void println(java.lang.String s)
             throws java.io.IOException
Send a line of text to the file with a trailing new line appropriate for the o/s.

Parameters:
s - The string to send.

java.io.IOException

println

public void println()
             throws java.io.IOException
Send a newline to the file.

java.io.IOException

writeLine

public void writeLine(java.lang.String s)
               throws java.io.IOException
Send a line of text to the file with a trailing new line appropriate for the o/s.

Parameters:
s - The string to send.

java.io.IOException

print

public void print(java.lang.String s)
           throws java.io.IOException
Send a line of text to the file.

Newlines embedded in the string are properly converted. If that is not what you want, call write() instead.

Parameters:
s - The string to send.

Throws:
java.io.IOException


Copyright ©2004 Paul Wheaton All Rights Reserved