Java File to String fileToString(String filename)

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

Description

file To String

License

Apache License

Declaration

public static String fileToString(String filename) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;

public class Main {
    public static String fileToString(String filename) {
        String result = null;/*from w  ww. j  a  va 2  s.c o  m*/
        DataInputStream in = null;
        try {
            byte[] buffer = new byte[(int) new File(filename).length()];
            in = new DataInputStream(new FileInputStream(filename));
            in.readFully(buffer);
            result = new String(buffer);
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}

Related

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