Java FileInputStream Read readFile(String filename)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String filename) 

Method Source Code


//package com.java2s;
/*// w  w w  .  ja  v a  2 s  .  c o  m
 * --------------------------------------------------------
 * Module Name : binding-upnp
 * Version : 0.1-SNAPSHOT
 *
 * Software Name : HomeNap
 * Version : 0.1-SNAPSHOT
 *
 * Copyright ? 28/06/2012 ? 31/12/2013 France T?l?com
 * This software is distributed under the Apache 2.0 license,
 * the text of which is available at http://www.apache.org/licenses/LICENSE-2.0.html
 * or see the "LICENSE-2.0.txt" file for more details.
 *
 * --------------------------------------------------------
 * File Name   : ${NAME}
 *
 * Created     :
 * Author(s)   : Remi Druilhe
 *
 * Description :
 *
 * --------------------------------------------------------
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static String readFile(String filename) {
        File f = new File(filename);
        InputStream stream = null;
        try {
            stream = new FileInputStream(f);
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        int ch = 0;
        StringBuffer buffer = new StringBuffer();
        int len;
        try {
            len = stream.available();
            if (len != -1) {
                for (int i = 0; i < len; i++)
                    if ((ch = stream.read()) != -1)
                        buffer.append((char) ch);
            }
        } catch (IOException e) {

            e.printStackTrace();
        }

        String xmlFile = buffer.toString();
        return xmlFile;
    }
}

Related

  1. readFile(String filename)
  2. readfile(String filename)
  3. readFile(String filename)
  4. readFile(String fileName)
  5. readFile(String fileName)
  6. readFile(String fileName)
  7. readFile(String filename)
  8. readFile(String filename)
  9. readFile(String filename)