Java FileInputStream Read readFile(String sFileName)

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

Description

Legge un file

License

Open Source License

Parameter

Parameter Description
String - sFileName (nome file)

Return

StringBuffer - contenuto del file

Declaration

public static StringBuffer readFile(String sFileName) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    /**/*from  w  ww .  j a  v  a2s. c  om*/
     * Legge un file
     *
     * @param String - sFileName (nome file)
     * @return StringBuffer - contenuto del file 
     */
    public static StringBuffer readFile(String sFileName) throws IOException {
        int nI = 0;
        byte buf[] = new byte[4096];
        StringBuffer sHold = new StringBuffer();
        BufferedInputStream bfin = null;

        try {
            bfin = new BufferedInputStream(new FileInputStream(sFileName));
            while ((nI = bfin.read(buf)) != -1) {
                if (nI != -1)
                    sHold.append(new String(buf, 0, nI));
            }
            bfin.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sHold;
    }
}

Related

  1. readFile(String path, Properties store)
  2. readFile(String path, String encoding)
  3. readFile(String path, String root, OutputStream out)
  4. readFile(String pPathToFile)
  5. readFile(String resource)
  6. readFileAsBinary(File file)
  7. readFileAsInputStream(File file)
  8. readFileAsInputStream(String fileName)
  9. readFileAsProperties(File file)