|
Basic 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
:
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.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 |
public InOut()
Method Detail |
public static final boolean canWrite(java.lang.String fileName)
fileName
- a file name
public static final boolean canWriteImage(java.lang.String fileName)
fileName
- a file name
public static final boolean canRead(java.lang.String fileName)
fileName
- a file name
public static final boolean canReadImage(java.lang.String fileName)
fileName
- a file name
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 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 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 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
form
|
author context |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |