Java RandomAccessFile Read readFile(String absoluteFileName)

Here you can find the source of readFile(String absoluteFileName)

Description

Fills the contents of the file given to a String

License

Open Source License

Parameter

Parameter Description
absoluteFileName a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static String readFile(String absoluteFileName) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.IOException;

import java.io.RandomAccessFile;

public class Main {
    /**//  w  w  w.ja  v a 2  s. c o  m
     * Fills the contents of the file given to a String
     * 
     * @param absoluteFileName
     * @return
     * @throws IOException
     */
    public static String readFile(String absoluteFileName) throws IOException {
        File file = new File(absoluteFileName);
        byte buffer[] = null;
        RandomAccessFile raf = null;
        try {
            raf = new RandomAccessFile(absoluteFileName, "r");
            int fileSize = (int) file.length();
            buffer = new byte[fileSize];
            raf.read(buffer, 0, fileSize);
        } finally {
            if (raf != null)
                raf.close();
        }
        return new String(buffer, "ISO-8859-9");
    }
}

Related

  1. readAByte(ReadableByteChannel readChannel)
  2. readFile(File f)
  3. readFile(File file)
  4. readFile(File file)
  5. readFile(final File file)
  6. readFile(String file)
  7. readFile(String file)
  8. readFile(String filename)
  9. readFile(String filePath)