|
All Methods zio package context |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object zio.InOut
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
:
The read and write methods in this class were written to be
thread safe but this feature has not been tested.
The image reading and writing methods can be used to convert
from one image type to another.String contents = InOut.readText("source.txt");
InOut.writeText("target.txt",contents);
Error handling can be overridden by subclassing the Zio
class.
Constructor Summary | |
InOut()
|
Method Summary | |
static boolean |
canRead(java.io.File file)
Tests whether file can be read. |
static boolean |
canRead(java.lang.String fileName)
Tests whether file can be read. |
static boolean |
canReadImage(java.io.File file)
Tests whether file can be read. |
static boolean |
canReadImage(java.lang.String fileName)
Tests whether file can be read. |
static boolean |
canWrite(java.io.File file)
Tests whether file can be written. |
static boolean |
canWrite(java.lang.String fileName)
Tests whether file can be written. |
static boolean |
canWriteImage(java.io.File file)
Tests whether file can be written. |
static boolean |
canWriteImage(java.lang.String fileName)
Tests whether file can be written. |
static void |
main(java.lang.String[] files)
used for testing, may be arbitrarily changed |
static java.awt.image.BufferedImage |
readImage(java.io.File file)
Reads a gif, jpg or png image. |
static java.awt.image.BufferedImage |
readImage(java.lang.String fileName)
Reads a gif, jpg or png image. |
static java.lang.String |
readText(java.io.File file)
Read a text file into a String. |
static java.lang.String |
readText(java.lang.String fileName)
Read a text file into a String. |
static void |
writeImage(java.io.File file,
java.awt.image.BufferedImage content)
Writes a jpg or png image. |
static void |
writeImage(java.lang.String fileName,
java.awt.image.BufferedImage content)
Writes a jpg or png image. |
static void |
writeText(java.io.File file,
java.lang.String content)
Writes a String to a file. |
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 |
public InOut()
Method Detail |
public static final boolean canWrite(java.lang.String fileName)
canWrite()
method in Java's File
class.
fileName
- a file name
public static final boolean canWrite(java.io.File file)
canWrite()
method in Java's File
class.
file
- a File
object
public static final boolean canWriteImage(java.lang.String fileName)
fileName
- a file name
public static final boolean canWriteImage(java.io.File file)
file
- a File
object
public static final boolean canRead(java.lang.String fileName)
fileName
- a file name
public static final boolean canRead(java.io.File file)
file
- a File
object
public static final boolean canReadImage(java.lang.String fileName)
fileName
- a file name
public static final boolean canReadImage(java.io.File file)
file
- a File
object
public static final java.lang.String readText(java.lang.String fileName)
fileName
- the name of the file to be read
String
containing the entire contents of the filepublic static final java.lang.String readText(java.io.File file)
file
- a file
object identifying the file to be read
String
representing the entire contents of the filepublic static final void writeText(java.lang.String fileName, java.lang.String content)
fileName
- the name of the file to be writtencontent
- the new contents of the named filepublic static final void writeText(java.io.File file, java.lang.String content)
file
- a file
object identifying the file to be written oncontent
- the new contents of the named filepublic static final java.awt.image.BufferedImage readImage(java.lang.String fileName)
java.awt.image.BufferedImage
to use this.
fileName
- the name of the image file to be read, must end with .jpg or
.png
BufferedImage
formpublic static final java.awt.image.BufferedImage readImage(java.io.File file)
java.awt.image.BufferedImage
to use this.
file
- a file
object referencing the file to be read;
file name must end with .jpg or .png.
BufferedImage
formpublic static final void writeImage(java.lang.String fileName, java.awt.image.BufferedImage content)
java.awt.image.BufferedImage
to use this.
fileName
- the name of the file to be written;
must end with .jpg or .pngcontent
- the image in BufferedImage
formpublic static final void writeImage(java.io.File file, java.awt.image.BufferedImage content)
java.awt.image.BufferedImage
to use this.
file
- a file
object referencing the file to be written;
file name must end with .jpg or .pngcontent
- the image in BufferedImage
formpublic static void main(java.lang.String[] files)
|
author context |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |