Basic Methods
zio package

context

zio
Class InOut


java.lang.Object

  extended byzio.InOut


public class InOut
extends java.lang.Object

This class contains methods for reading and writing entire files: either text files or image files. If image files, the image type must be jpg or png. Here is an example that reads in the contents of the file source.txt and then copies that contents to the file target.txt:

String contents = InOut.readText("source.txt");
InOut.writeText("target.txt",contents);

Error handling can be overridden by subclassing the Zio class.

Version:
Jul 22, 2005
Author:
copyright 2005 by J Adrian Zimmer
Licensed under the Open Software License version 2.1

Constructor Summary
InOut()
           
 
Method Summary
static boolean canRead(java.lang.String fileName)
          Tests whether file can be read.
static boolean canReadImage(java.lang.String fileName)
          Tests whether file can be read.
static boolean canWrite(java.lang.String fileName)
          Tests whether file can be written.
static boolean canWriteImage(java.lang.String fileName)
          Tests whether file can be written.
static java.awt.image.BufferedImage readImage(java.lang.String fileName)
          Reads a gif, jpg or png image.
static java.lang.String readText(java.lang.String fileName)
          Read a text file into a String.
static void writeImage(java.lang.String fileName, java.awt.image.BufferedImage content)
          Writes a jpg or png image.
static void writeText(java.lang.String fileName, java.lang.String content)
          Writes a String to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InOut


public InOut()
Method Detail

canWrite


public static final boolean canWrite(java.lang.String fileName)
Tests whether file can be written.

Parameters:
fileName - a file name
Returns:
true iff named file can be written

canWriteImage


public static final boolean canWriteImage(java.lang.String fileName)
Tests whether file can be written. Checks two things: Can the file be written? And, is the image format indicated by the extension supported?

Parameters:
fileName - a file name
Returns:
true iff named file can be written

canRead


public static final boolean canRead(java.lang.String fileName)
Tests whether file can be read.

Parameters:
fileName - a file name
Returns:
true iff named file can be read

canReadImage


public static final boolean canReadImage(java.lang.String fileName)
Tests whether file can be read. Checks two things: Can the file be read? And, is the image format indicated by the extension supported?

Parameters:
fileName - a file name
Returns:
true iff named file can be read

readText


public static final java.lang.String readText(java.lang.String fileName)
Read a text file into a String. Reads an entire file. Meant to use for short text files.

Parameters:
fileName - the name of the file to be read
Returns:
a String containing the entire contents of the file

writeText


public static final void writeText(java.lang.String fileName,
                                   java.lang.String content)
Writes a String to a file. Meant to be used for short text files. The string will become the entire contents of the file.

Parameters:
fileName - the name of the file to be written
content - the new contents of the named file

readImage


public static final java.awt.image.BufferedImage readImage(java.lang.String fileName)
Reads a gif, jpg or png image.
You must import java.awt.image.BufferedImage to use this.

Parameters:
fileName - the name of the image file to be read, must end with .jpg or .png
Returns:
the image in BufferedImage form

writeImage


public static final void writeImage(java.lang.String fileName,
                                    java.awt.image.BufferedImage content)
Writes a jpg or png image.
You must import java.awt.image.BufferedImage to use this.

Parameters:
fileName - the name of the file to be written; must end with .jpg or .png
content - the image in BufferedImage form

author
context