FileDocCategorySizeDatePackage
OpenRandomFileTest.javaAPI DocAndroid 1.5 API2798Wed May 06 22:41:04 BST 2009tests.api.java.io

OpenRandomFileTest

public class OpenRandomFileTest extends TestCase
TODO Type description

Fields Summary
Constructors Summary
public OpenRandomFileTest()

        super();
    
Methods Summary
public static voidmain(java.lang.String[] args)

        new OpenRandomFileTest().testOpenEmptyFile();
    
public voidtestOpenEmptyFile()

        try {
            File file = File.createTempFile("test", "tmp");
            assertTrue(file.exists());
            file.deleteOnExit();

            String fileName = file.getCanonicalPath();
            RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
            raf.close();
        } catch (IOException ex) {
            fail(ex.getLocalizedMessage());
        }
    
public voidtestOpenNonEmptyFile()

        try {
            File file = File.createTempFile("test", "tmp");
            assertTrue(file.exists());
            file.deleteOnExit();
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            fos.close();

            String fileName = file.getCanonicalPath();
            RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
            raf.close();
        } catch (IOException ex) {
            fail(ex.getLocalizedMessage());
        }