## edu.stanford.nlp.io
Class FileUtils

    java.lang.Object
      edu.stanford.nlp.io.FileUtils

    public class FileUtils

extends Object

Field Summary
`static String` `eolChar`

Method Summary
`static File` `backupFile(File file)`
`static String` `backupName(String filename)`
`static File` `ensureDir(File tgtDir)` Given a filepath, makes sure a directory exists there.
`static BufferedReader` `getBufferedFileReader(String filename)`
`static BufferedReader` `getBufferedFileReader(String filename, String encoding)`
`static InputStream` `getBZip2PipedInputStream(String filename)`
`static OutputStream` `getBZip2PipedOutputStream(String filename)`
`static String` `getExtension(String fileName)`
`static InputStream` `getFileInputStream(String filename)` Get a input file stream (automatically gunzip/bunzip2 depending on file extension)
`static OutputStream` `getFileOutputStream(String filename)` Get a output file stream (automatically gzip/bzip2 depending on file extension)
`static File` `getJNLPLocalScratch()` A JavaNLP specific convenience routine for obtaining the current scratch directory for the machine you're currently running on.
`static PrintWriter` `getPrintWriter(String filename)`
`static PrintWriter` `getPrintWriter(String filename, String encoding)`
`static List<String>` `linesFromFile(String filename)` Returns the contents of a file as a list of strings.
`static List<String>` `linesFromFile(String filename, String encoding)` Returns the contents of a file as a list of strings.
`static void` `main(String[] args)`
`static Set<String>` `readColumnSet(String infile, int field)` Read column as set
`static Map<String,String>` `readMap(String filename)`

`static

`<C> List<C>`

`

`readObjectFromColumns(Class objClass, String filename, String[] fieldNames, String delimiter)`

`static boolean` `renameToBackupName(File file)`
`static String` `stringFromFile(String filename)` Returns the contents of a file as a single string.
`static String` `stringFromFile(String filename, String encoding)` Returns the contents of a file as a single string.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### eolChar

    public static final String eolChar

Method Detail

### getFileInputStream

    public static InputStream getFileInputStream(String filename)
                                          throws IOException

  Get a input file stream (automatically gunzip/bunzip2 depending on file extension)

  Parameters:
    `filename` - Name of file to open
  Returns:
    Input stream that can be used to read from the file
  Throws:
    `IOException` - if there are exceptions opening the file

### getFileOutputStream

    public static OutputStream getFileOutputStream(String filename)
                                            throws IOException

  Get a output file stream (automatically gzip/bzip2 depending on file extension)

  Parameters:
    `filename` - Name of file to open
  Returns:
    Output stream that can be used to write to the file
  Throws:
    `IOException` - if there are exceptions opening the file

### getBufferedFileReader

    public static BufferedReader getBufferedFileReader(String filename)
                                                throws IOException

  Throws:
    `IOException`

### getBufferedFileReader

    public static BufferedReader getBufferedFileReader(String filename,
                                                       String encoding)
                                                throws IOException

  Throws:
    `IOException`

### getPrintWriter

    public static PrintWriter getPrintWriter(String filename)
                                      throws IOException

  Throws:
    `IOException`

### getPrintWriter

    public static PrintWriter getPrintWriter(String filename,
                                             String encoding)
                                      throws IOException

  Throws:
    `IOException`

### getBZip2PipedInputStream

    public static InputStream getBZip2PipedInputStream(String filename)
                                                throws IOException

  Throws:
    `IOException`

### getBZip2PipedOutputStream

    public static OutputStream getBZip2PipedOutputStream(String filename)
                                                  throws IOException

  Throws:
    `IOException`

### readColumnSet

    public static Set<String> readColumnSet(String infile,
                                            int field)
                                     throws IOException

  Read column as set

  Parameters:
    `infile` - - filename
    `field` - index of field to read
  Returns:
    a set of the entries in column field
  Throws:
    `IOException`

### readObjectFromColumns

    public static <C> List<C> readObjectFromColumns(Class objClass,
                                                    String filename,
                                                    String[] fieldNames,
                                                    String delimiter)
                                         throws IOException,
                                                InstantiationException,
                                                IllegalAccessException,
                                                NoSuchFieldException,
                                                NoSuchMethodException,
                                                InvocationTargetException

  Throws:
    `IOException`
    `InstantiationException`
    `IllegalAccessException`
    `NoSuchFieldException`
    `NoSuchMethodException`
    `InvocationTargetException`

### readMap

    public static Map<String,String> readMap(String filename)
                                      throws IOException

  Throws:
    `IOException`

### stringFromFile

    public static String stringFromFile(String filename)

  Returns the contents of a file as a single string. The string may be empty, if the file is empty. If there is an IOException, it is caught and null is returned.

### stringFromFile

    public static String stringFromFile(String filename,
                                        String encoding)

  Returns the contents of a file as a single string. The string may be empty, if the file is empty. If there is an IOException, it is caught and null is returned. Encoding can also be specified.

### linesFromFile

    public static List<String> linesFromFile(String filename)

  Returns the contents of a file as a list of strings. The list may be empty, if the file is empty. If there is an IOException, it is caught and null is returned.

### linesFromFile

    public static List<String> linesFromFile(String filename,
                                             String encoding)

  Returns the contents of a file as a list of strings. The list may be empty, if the file is empty. If there is an IOException, it is caught and null is returned. Encoding can also be specified

### backupName

    public static String backupName(String filename)

### backupFile

    public static File backupFile(File file)

### renameToBackupName

    public static boolean renameToBackupName(File file)

### getJNLPLocalScratch

    public static File getJNLPLocalScratch()

  A JavaNLP specific convenience routine for obtaining the current scratch directory for the machine you're currently running on.

### ensureDir

    public static File ensureDir(File tgtDir)
                          throws Exception

  Given a filepath, makes sure a directory exists there. If not, creates and returns it. Same as ENSURE-DIRECTORY in CL.

  Throws:
    `Exception`

### main

    public static void main(String[] args)

### getExtension

    public static String getExtension(String fileName)

Stanford NLP Group