Here you can find the source of loadTestProgram(final Class> resourceClass, final String fileName)
Parameter | Description |
---|---|
resourceClass | The class from which to get the resource |
fileName | The file name |
Parameter | Description |
---|---|
IOException | if the file failed to load. |
public static String loadTestProgram(final Class<?> resourceClass, final String fileName) throws IOException
//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(); } }