Java File to String fileToString(String fileName)

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

Description

file To String

License

Open Source License

Declaration

public static String fileToString(String fileName)
            throws FileNotFoundException 

Method Source Code

//package com.java2s;
import java.io.*;

import java.util.Scanner;

public class Main {
    public static String fileToString(String fileName)
            throws FileNotFoundException {
        File file = new File(fileName);
        return fileToString(file);
    }//from  w w w  . ja  va2s  .c o  m

    public static String fileToString(File file)
            throws FileNotFoundException {
        String s = null;
        try {
            s = new Scanner(file).useDelimiter("\\Z").next();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return s;
    }
}

Related

  1. fileToString(String filename)
  2. fileToString(String filename)
  3. fileToString(String fileName)
  4. fileToString(String fileName)
  5. fileToString(String filename)
  6. fileToString(String fileName)
  7. fileToString(String fileName, String timestamp, String adapterName)
  8. fileToString(String filePath)
  9. fileToString(String filePath, String encoding)