Example usage for java.io RandomAccessFile close

List of usage examples for java.io RandomAccessFile close

Introduction

In this page you can find the example usage for java.io RandomAccessFile close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this random access file stream and releases any system resources associated with the stream.

Usage

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    RandomAccessFile rf = new RandomAccessFile("test.dat", "rw");
    for (int i = 0; i < 10; i++)
        rf.writeDouble(i * 1.414);//from  w  w  w . j  ava2 s  . c o m
    rf.close();
    rf = new RandomAccessFile("test.dat", "rw");
    rf.seek(5 * 8);
    rf.writeDouble(47.0001);
    rf.close();
    rf = new RandomAccessFile("test.dat", "r");
    for (int i = 0; i < 10; i++)
        System.out.println("Value " + i + ": " + rf.readDouble());
    rf.close();

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    RandomAccessFile file = new RandomAccessFile(new File("scores.html"), "rw");
    for (int i = 1; i <= 6; i++) {
        System.out.println(file.readLine());
    }/*from  w ww . j  a v a 2s.  c o m*/
    file.close();
}

From source file:RawDataFromImageFilePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from w  w  w. j  a  v a  2 s.  c  o m*/
        PdfWriter.getInstance(document, new FileOutputStream("RawDataFromImageFilePDF.pdf"));
        document.open();

        RandomAccessFile rf = new RandomAccessFile("logo.png", "r");
        int size = (int) rf.length();
        byte imext[] = new byte[size];
        rf.readFully(imext);
        rf.close();

        Image img1 = Image.getInstance(imext);
        img1.setAbsolutePosition(50, 500);
        document.add(img1);

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:RawDataFromImageFileAndManipulationPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//  w w  w  .  j  av a 2s.  c  om
        PdfWriter.getInstance(document, new FileOutputStream("RawDataFromImageFileAndManipulationPDF.pdf"));
        document.open();

        RandomAccessFile rf = new RandomAccessFile("logo.png", "r");
        int size = (int) rf.length();
        byte imext[] = new byte[size];
        rf.readFully(imext);
        rf.close();

        for (int i = 0; i < imext.length; i++) {
            imext[i] = (byte) (imext[i] + 3);
        }

        Image img1 = Image.getInstance(100, 100, 3, 8, imext);
        img1.setAbsolutePosition(200, 200);
        document.add(img1);

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipInputStream zipinputstream = new ZipInputStream(new FileInputStream("filename"));
    ZipEntry zipentry = zipinputstream.getNextEntry();
    while (zipentry != null) {
        String entryName = zipentry.getName();
        File newFile = new File(entryName);
        String directory = newFile.getParent();
        if (directory == null) {
            if (newFile.isDirectory())
                break;
        }/*from  w  w w . ja  v a  2s. co m*/
        RandomAccessFile rf = new RandomAccessFile(entryName, "r");
        String line;
        if ((line = rf.readLine()) != null) {
            System.out.println(line);
        }
        rf.close();
        zipinputstream.closeEntry();
        zipentry = zipinputstream.getNextEntry();
    }
    zipinputstream.close();
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    RandomAccessFile raf = new RandomAccessFile(new File("temp.tmp"), "rw");
    raf.writeInt(1);//from   w w  w  .j av a  2s .com
    for (int i = 0; i < 10; i++) {
        raf.seek(raf.length() - 4);
        raf.writeInt(raf.readInt());
    }
    raf.close();

}

From source file:Main.java

public static void main(String[] args) {
    try {/*from   www  . j a va2  s. c o  m*/
        byte[] b = { 1 };

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");
        raf.write(b);

        // set the file pointer at 0 position
        raf.seek(0);

        System.out.println(raf.readByte());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File f = new File("filename");
    RandomAccessFile raf = new RandomAccessFile(f, "rw");

    // Read a character
    char ch = raf.readChar();

    // Seek to end of file
    raf.seek(f.length());/* ww  w .  j  a va 2 s .co m*/

    // Append to the end
    raf.writeChars("aString");
    raf.close();
}

From source file:BridgeBasics.java

public static void main(String args[]) throws Exception {
    RServices rs = DirectJNI.getInstance().getRServices();
    rs.consoleSubmit("k=function(x){x*5}");

    System.out/*from  w  ww  .  ja  va  2s  .c  o m*/
            .println("////////////////////////////////" + rs.callAndConvert(new RFunctionObjectName("k"), 45));

    //rs.putAndAssign(new RUnknown(o.getValue()), "b");
    //System.out.println("-------------------------------"+rs.print("h"));

    /*
            
    RServices rs =
       ServerManager.createR("toto"); 
            
       RObject ro1 = 
    rs.getObject("structure(list(1,2), caption = \"foo\")");
       RObject ro2 = 
    rs.getReference("structure(list(1,2), caption = \"foo\")");
       System.out.println(rs.callAndConvert("str", ro1));
       System.out.println(rs.callAndConvert("str", ro2));
            
            
    rs.die();
            
    if (true) return;
    */

    rs = DirectJNI.getInstance().getRServices();
    GDDevice device = rs.newDevice(400, 400);
    rs.consoleSubmit("plot(pressure)");
    System.out.println(rs.getStatus());
    byte[] buffer = device.getPng();
    RandomAccessFile raf = new RandomAccessFile("c:/te.png", "rw");
    raf.setLength(0);
    raf.write(buffer);
    raf.close();

    //rs.evaluate("x=2;y=8",2);

    /*
    RS3 s3=(RS3)rs.getReference("packageDescription('stats')");
    System.out.println("s="+Arrays.toString(s3.getClassAttribute()));
    s3.setClassAttribute(new String[] {s3.getClassAttribute()[0], "aaa"});
    rs.assignReference("f",s3);
    //rs.call("print",new RObjectName("f"));
    //System.out.println("log=" + rs.getStatus());
            
    rs.consoleSubmit("print(class(f))");
    System.out.println("log=" + rs.getStatus());
            
    RChar s = (RChar) rs.call("paste", new RChar("str1"), new RChar("str2"), new RNamedArgument("sep", new RChar(
    "--")));
    System.out.println("s=" + s);
    */

    System.exit(0);

}

From source file:SenBench.java

public static void main(String[] args) {
    try {// w ww .  j  ava 2  s.  c o  m
        if (args.length == 0) {
            System.out.println("usage: java SenBench file [file ..]");
            System.exit(2);
        }

        StringTagger tagger = StringTagger.getInstance(Locale.JAPANESE);

        long processed = 0;
        long nbytes = 0;
        long nchars = 0;

        long start = System.currentTimeMillis();
        for (int a = 0; a < args.length; a++) {
            String text = "";
            try {
                RandomAccessFile raf = new RandomAccessFile(args[a], "r");
                byte[] buf = new byte[(int) raf.length()];
                raf.readFully(buf);
                raf.close();
                text = new String(buf, encoding);
                nbytes += buf.length;
                nchars += text.length();
            } catch (IOException ioe) {
                log.error(ioe);
                continue;
            }

            long s_start = System.currentTimeMillis();
            for (int c = 0; c < repeat; c++)
                doWork(tagger, text);
            long s_end = System.currentTimeMillis();
            processed += (s_end - s_start);
        }
        long end = System.currentTimeMillis();
        System.out.println("number of files: " + args.length);
        System.out.println("number of repeat: " + repeat);
        System.out.println("number of bytes: " + nbytes);
        System.out.println("number of chars: " + nchars);
        System.out.println("total time elapsed: " + (end - start) + " msec.");
        System.out.println("analysis time: " + (processed) + " msec.");
    } catch (Exception e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
}