Java Scanner Read readFile(String fileName)

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

Description

Reads a file relative to the CMPUT391 directory and returns a String.

License

Apache License

Declaration

public static String readFile(String fileName) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;
import java.util.*;

public class Main {
    /**/*w  ww  .ja  v  a2s .c o m*/
     * Reads a file relative to the CMPUT391 directory and returns a String.
     */
    public static String readFile(String fileName) throws IOException {
        File inFile = new File("catalina/webapps/CMPUT391F/" + fileName);
        //throw new IOException("EXPECTED FILE: "+inFile.getAbsolutePath());

        String out = "";
        Scanner scanner = new Scanner(new FileInputStream(inFile));
        out = scanner.useDelimiter("\\Z").next();
        return out;
    }
}

Related

  1. readFile(final File f)
  2. readFile(String file_name)
  3. readFile(String filename)
  4. readFile(String fileName)
  5. readFile(String fileName)
  6. readFile(String filePath)
  7. readFile(String filePath)
  8. readFile(String filePath)
  9. readFile(String path)