Skip to content

Instantly share code, notes, and snippets.

@jimjam88
Created January 22, 2014 14:30
Show Gist options
  • Save jimjam88/8559618 to your computer and use it in GitHub Desktop.
Save jimjam88/8559618 to your computer and use it in GitHub Desktop.
Read the contents of a file into a string
// Imports required
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
* Read in a file.
*
* @param path The explicit path to the file to read
* @return The contents of the file as a string
* @throws FileNotFoundException If there's a problem reading the file.
*/
final public static String readFile(String path) throws FileNotFoundException
{
return new Scanner(new File(path)).useDelimiter("\\Z").next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment