FileDocCategorySizeDatePackage
FileIOTest.javaAPI DocExample1626Sun Jan 25 14:59:14 GMT 2004regress

FileIOTest

public class FileIOTest extends TestCase

Fields Summary
public static final String
FILENAME
Test File name. This file is created in build.xml
public static final String
MESSAGE
Test string.
Constructors Summary
public FileIOTest()
Constructor sets up initial state data file state for testing


	           
	  
		try {
			PrintWriter out = new PrintWriter(new FileWriter(FILENAME));
			out.print(MESSAGE);	// NOT println; FileToString doesn't handle.
			out.close();
		} catch (IOException ex) {
			throw new IllegalStateException("FileIOTest: can't create " + FILENAME);
		}
	
Methods Summary
public voidtestCopyFile()

		String fileName = FILENAME;
		String targetFileName = FILENAME + ".bak";
		try {
			FileIO.copyFile(fileName, targetFileName);
			String s1 = FileIO.readerToString(new FileReader(fileName));
			String s2 = FileIO.readerToString(new FileReader(targetFileName));
			assertEquals(s1, s2);
		} catch (IOException ex) {
			System.err.println(ex);
			throw new IllegalArgumentException(ex.toString());
		}
	
public voidtestReaderToString()

		try {
			String s = FileIO.readerToString(new FileReader(FILENAME));

			// Make sure that readerToString really reads from the file.
			assertEquals(s, MESSAGE);

			// Make sure that readerToString doesn't append gunk like
			// extraneous nulls.
			assertEquals(s.length(), new File(FILENAME).length());

		} catch (Exception ex) {
			System.err.println(ex);
			throw new IllegalArgumentException(ex.toString());
		}