Java FileInputStream Read readfile(File path)

Here you can find the source of readfile(File path)

Description

readfile

License

Open Source License

Declaration

public static String readfile(File path) 

Method Source Code


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

import java.io.*;

public class Main {
    public static String readfile(String path) {
        String resp = "";
        File f;//from   w  w w. j av a2 s  .  c  o  m
        FileInputStream inp;
        try {
            f = new File(path);
            inp = new FileInputStream(f);
            byte[] bf = new byte[(int) f.length()];
            inp.read(bf);
            resp = new String(bf, "UTF-8");
            inp.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return resp;
    }

    public static String readfile(File path) {
        String resp = "";
        FileInputStream inp;
        try {
            inp = new FileInputStream(path);
            byte[] bf = new byte[(int) path.length()];
            inp.read(bf);
            resp = new String(bf, "UTF-8");
            inp.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return resp;
    }
}

Related

  1. readFile(File file, String encoding)
  2. readFile(File file, String encoding)
  3. readFile(File file, String encoding)
  4. readFile(File fyl)
  5. readFile(File path)
  6. readFile(File source)
  7. readFile(File src)
  8. readFile(File srcFile, OutputStream destStream)
  9. readFile(File target)