Java Scanner Read loadTestProgram(final Class resourceClass, final String fileName)

Here you can find the source of loadTestProgram(final Class resourceClass, final String fileName)

Description

Loads a test program from a resource.

License

Open Source License

Parameter

Parameter Description
resourceClass The class from which to get the resource
fileName The file name

Exception

Parameter Description
IOException if the file failed to load.

Return

The test program as a String

Declaration

public static String loadTestProgram(final Class<?> resourceClass, final String fileName) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.io.InputStream;

import java.util.Scanner;

public class Main {
    /**/*from www  . j  a  v  a2s.  c  o m*/
     * Loads a test program from a resource.
     * 
     * @param resourceClass
     *                The class from which to get the resource
     * @param fileName
     *                The file name
     * @return The test program as a String
     * @throws IOException
     *                 if the file failed to load.
     */
    public static String loadTestProgram(final Class<?> resourceClass, final String fileName) throws IOException {
        InputStream stream = resourceClass.getResourceAsStream("/" + fileName);

        if (stream == null) {
            throw new IOException("Cannot find file: " + fileName);
        }

        return new Scanner(stream).useDelimiter("\\A").next();
    }
}

Related

  1. loadIntArray(Scanner reader)
  2. loadNDimDoubleMatrix(Scanner reader, int numberOfDim, Object nmatrix)
  3. loadNDimDoubleMatrixRec(Scanner reader, int[] dim, Object nmatrix)
  4. loadSentencesMap(String path)
  5. loadSolution(File file)
  6. loadTimeseries(File file, String delimeter, int _amountOfLines)
  7. read()
  8. read(Class clazz, String f)
  9. readArr(Scanner in, int n)