Java File to String fileToString(File f)

Here you can find the source of fileToString(File f)

Description

file To String

License

Creative Commons License

Declaration

public static String fileToString(File f) throws FileNotFoundException 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class Main {
    public static String fileToString(File f) throws FileNotFoundException {
        Scanner m = new Scanner(f);
        String s = "";
        while (m.hasNextLine()) {
            s = s + m.nextLine().trim() + "\n";
        }// w  ww. ja  va  2 s. c om
        m.close();
        return s.trim();
    }
}

Related

  1. fileToStream(File source, OutputStream target)
  2. fileToStream(final File file)
  3. fileToStream(String filename)
  4. fileToString(File f)
  5. fileToString(File f)
  6. fileToString(File f)
  7. fileToString(File f)
  8. fileToString(File f)
  9. fileToString(File f)