Java File to String fileToString(String file, String encoding)

Here you can find the source of fileToString(String file, String encoding)

Description

file To String

License

Open Source License

Declaration

static public String fileToString(String file, String encoding) throws Exception 

Method Source Code

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

import java.io.ByteArrayOutputStream;

import java.io.FileInputStream;

public class Main {

    static public String fileToString(String file, String encoding) throws Exception {
        FileInputStream fis = new FileInputStream(file);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[10240];
        int len = fis.read(buffer, 0, buffer.length);
        while (len > 0) {
            baos.write(buffer, 0, len);/*from w w  w.  jav a2 s.c o m*/
            len = fis.read(buffer, 0, buffer.length);
        }
        fis.close();

        return baos.toString(encoding);
    }
}

Related

  1. fileToString(InputStream file)
  2. fileToString(InputStream inputStream)
  3. fileToString(String file)
  4. fileToString(String file)
  5. fileToString(String file)
  6. FileToString(String file_name)
  7. fileToString(String filename)
  8. fileToString(String fileName)
  9. fileToString(String fileName)