Java File to String fileToString(String file)

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

Description

file To String

License

Open Source License

Declaration

public static String fileToString(String file) 

Method Source Code

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

import java.io.BufferedReader;
import java.io.FileInputStream;

import java.io.InputStreamReader;

import java.io.File;

public class Main {
    public static String fileToString(String file) {
        try {// w  w w .  ja  va2 s.  co  m
            File fileDir = new File(file);

            BufferedReader in = new BufferedReader(new InputStreamReader(
                    new FileInputStream(fileDir), "UTF8"));

            String str, strOut = "";

            while ((str = in.readLine()) != null) {
                str = str.replace("\uFEFF", "");
                strOut += str + "\r\n";
            }

            in.close();
            return strOut;
        }

        catch (Exception e) {
            return "";
        }
    }
}

Related

  1. fileToString(final File file, final String charsetName)
  2. fileToString(final String filePath)
  3. fileToString(InputStream file)
  4. fileToString(InputStream inputStream)
  5. fileToString(String file)
  6. fileToString(String file)
  7. fileToString(String file, String encoding)
  8. FileToString(String file_name)
  9. fileToString(String filename)