Example usage for org.apache.commons.io FileUtils readFileToString

List of usage examples for org.apache.commons.io FileUtils readFileToString

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils readFileToString.

Prototype

public static String readFileToString(File file) throws IOException 

Source Link

Document

Reads the contents of a file into a String using the default encoding for the VM.

Usage

From source file:Main.java

public static void main(String[] args) {
    File file = new File("sample.txt");

    String content = FileUtils.readFileToString(file);

    System.out.println("File content: " + content);
}

From source file:com.googlecode.promnetpp.research.main.CompareOutputMain.java

/**
 * @param args the command line arguments
 */// w  ww . j ava  2s. c  o  m
public static void main(String[] args) throws IOException, InterruptedException {
    for (String _fileName : GeneralData.fileNames) {
        fileName = _fileName;
        sourceCode = FileUtils.readFileToString(new File(fileName));
        System.out.println("Running seeds for file " + fileName);
        for (int seed : GeneralData.seeds) {
            doSeedRun(seed);
        }
    }
}

From source file:com.sdfl.compiler.CommandLineInterface.java

public static void main(String... pArgs) throws IOException {

    SDFLCompiler lCompiler = new OracleSDFLCompiler();
    String lCode = FileUtils.readFileToString(new File(pArgs[0]));

    lCompiler.getParameters().setDestinationFolder(new File("E:\\CompiledSDFL"));
    lCompiler.compile(lCode);//from ww  w. ja v  a 2 s. c o m

    for (CompilingException lCurEx : lCompiler.getCompilationExceptions()) {
        System.out.println(lCurEx);
    }
}

From source file:gov.nih.nci.caaersinstaller.util.CsmJaasFileCopier.java

public static void main(String args[]) throws Exception {

    //      File csmJaasTemplateFile = new File("/Users/Moni/temp/installer/postgres.csm_jaas.config");
    //      File csmJassConfigFile = new File("/Users/Moni/temp/installer/csm_jaas.config");

    File csmJaasTemplateFile = new File(args[0]);
    File csmJassConfigFile = new File(args[1]);

    if (csmJassConfigFile.exists()) {
        //append content of csmJaasTemplateFile to existing csmJaasConfigFile
        String csmJaasTemplateFileContent = FileUtils.readFileToString(csmJaasTemplateFile);
        StringBuilder stringBuilder = new StringBuilder(FileUtils.readFileToString(csmJassConfigFile));

        int start = stringBuilder.indexOf("caaers {");
        if (start != -1) {
            //If caaers context exisits then replace it.
            int end = stringBuilder.indexOf("};", start);
            end = end + 2;/* ww  w.j  a  va2  s . c o m*/
            stringBuilder.replace(start, end, csmJaasTemplateFileContent);
        } else {
            //if caaers context does not exist then add it 
            stringBuilder.append("\n");
            stringBuilder.append("\n");
            stringBuilder.append(csmJaasTemplateFileContent);
        }

        FileUtils.writeStringToFile(csmJassConfigFile, stringBuilder.toString());
        System.out.println("Modified csm_jaas.config to add caaers context");

    } else {
        //Create a new File with Contents of csmJaasTemplateFile
        FileUtils.copyFile(csmJaasTemplateFile, csmJassConfigFile);
        System.out.println("Created csm_jaas.config");

    }
}

From source file:com.sangupta.nutz.RandomProcessorTest.java

public static void main(String[] args) throws Exception {
    String fileName = "markdown syntax - basics";
    // fileName = "tabs";
    String s3 = "src/test/resources/markdown/" + fileName + ".text";
    String o3 = "src/test/resources/markdown/" + fileName + ".html";

    File file = new File(s3);
    String markup = FileUtils.readFileToString(file);

    MarkdownProcessor processor = new MarkdownProcessor();

    for (int i = 0; i < 20; i++) {
        long start = System.currentTimeMillis();
        String html = processor.toHtml(markup);
        long end = System.currentTimeMillis();

        System.out.println("Time taken in emitting HTML: " + (end - start) + " ms.");

        String out = FileUtils.readFileToString(new File(o3));
        boolean htmlEquals = HTMLComparer.compareHtml(out, html);
        System.out.println("HTML Equals: " + htmlEquals);
    }// www. j a v  a 2  s  .  c o m
}

From source file:com.googlecode.promnetpp.research.main.CoverageMain.java

/**
 * @param args the command line arguments
 *//*from   w  ww  .  j a  v a  2  s  .  c  o m*/
public static void main(String[] args) {
    try {
        System.out.println(GeneralData.seeds.length + " seeds available.");
        prepareCSVFile();
        for (String _fileName : GeneralData.fileNames) {
            fileName = _fileName;
            sourceCode = FileUtils.readFileToString(new File(fileName));
            System.out.println("Running seeds for file " + fileName);
            for (int seed : GeneralData.seeds) {
                doSeedRun(seed);
            }
        }
    } catch (IOException ex) {
        Logger.getLogger(CoverageMain.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InterruptedException ex) {
        Logger.getLogger(CoverageMain.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        cleanup();
    }
}

From source file:com.sangupta.nutz.PerformanceTestSuite.java

public static void main(String[] args) throws Exception {
    File dir = new File("src/test/resources/markdown");
    File[] files = dir.listFiles();

    for (File file : files) {
        if (file.getName().endsWith(".text")) {
            final String markup = FileUtils.readFileToString(file);

            String html = file.getAbsolutePath();
            html = html.replace(".text", ".html");
            html = FileUtils.readFileToString(new File(html));

            TestData testData = new TestData(markup, html);
            tests.add(testData);/*  w  ww.ja  va  2  s  . c o m*/
        }
    }

    TestResults nutz = runTests(new TestExecutor() {

        private MarkdownProcessor processor = new MarkdownProcessor();

        @Override
        public String convertMarkup(String markup) throws Exception {
            return processor.toHtml(markup);
        }

    });

    TestResults txtmark = runTests(new TestExecutor() {

        @Override
        public String convertMarkup(String markup) throws Exception {
            return Processor.process(markup);
        }

    });

    TestResults pegdown = runTests(new TestExecutor() {

        private PegDownProcessor processor = new PegDownProcessor();

        @Override
        public String convertMarkup(String markup) throws Exception {
            return processor.markdownToHtml(markup);
        }

    });

    System.out.println("\n\n\n\n\n");
    System.out.println("Nutz: " + nutz);
    System.out.println("Pegdown: " + pegdown);
    System.out.println("TextMark: " + txtmark);
}

From source file:com.osbcp.csssquasher.Squasher.java

/**
 * Main entry point for using the minifer as a stand alone application.
 * //from   w ww . j a  va  2s  .c  o  m
 * @param arguments First argument [0] should be the path of the CSS file that should be minified.
 * @throws Exception If any errors occur.
 */

public static void main(final String[] arguments) throws Exception {

    if (arguments.length != 1) {

        System.out.println("Usage: java -jar osbcp-css-squasher-x.y.z.jar [input file]");

    } else {

        File file = new File(arguments[0]);

        String contents = FileUtils.readFileToString(file);

        ResultObject results = Squasher.squash(contents);

        String compressedCSS = results.getCompressedCSS();

        System.out.println(compressedCSS);

    }

}

From source file:org.bimserver.javamodelchecker.WriteToJson.java

public static void main(String[] args) {
    try {/*w ww  .j  a v  a  2  s.c  o m*/
        ObjectMapper objectMapper = new ObjectMapper();
        ObjectNode rootNode = objectMapper.createObjectNode();
        ArrayNode array = objectMapper.createArrayNode();
        rootNode.set("modelcheckers", array);

        ObjectNode objectNode = objectMapper.createObjectNode();
        array.add(objectNode);
        objectNode.put("name", "Check window widths");
        objectNode.put("description", "Check window widths");
        objectNode.put("modelCheckerPluginClassName", "org.bimserver.javamodelchecker.JavaModelCheckerPlugin");
        objectNode.put("code",
                changeClassName(
                        FileUtils.readFileToString(
                                new File("src/org/bimserver/javamodelchecker/WindowWidthChecker.java")),
                        "WindowWidthChecker"));

        objectNode = objectMapper.createObjectNode();
        array.add(objectNode);
        objectNode.put("name", "Pass always");
        objectNode.put("description", "Pass always");
        objectNode.put("modelCheckerPluginClassName", "org.bimserver.javamodelchecker.JavaModelCheckerPlugin");
        objectNode.put("code", changeClassName(
                FileUtils.readFileToString(new File("src/org/bimserver/javamodelchecker/PassAlways.java")),
                "PassAlways"));

        objectNode = objectMapper.createObjectNode();
        array.add(objectNode);
        objectNode.put("name", "Fail always");
        objectNode.put("description", "Fail always");
        objectNode.put("modelCheckerPluginClassName", "org.bimserver.javamodelchecker.JavaModelCheckerPlugin");
        objectNode.put("code", changeClassName(
                FileUtils.readFileToString(new File("src/org/bimserver/javamodelchecker/FailAlways.java")),
                "FailAlways"));

        objectMapper.writerWithDefaultPrettyPrinter().writeValue(new File("modelcheckers.json"), rootNode);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:dpfmanager.shell.core.util.VersionUtil.java

public static void main(String[] args) {
    String version = args[0];//www .j  a va 2  s  . c o  m
    String baseDir = args[1];

    String issPath = baseDir + "/package/windows/DPF Manager.iss";
    String rpmPath = baseDir + "/package/linux/DPFManager.old.spec";
    String propOutput = baseDir + "/target/classes/version.properties";

    try {
        // Windows iss
        File issFile = new File(issPath);
        String issContent = FileUtils.readFileToString(issFile);
        String newIssContent = replaceLine(StringUtils.split(issContent, '\n'), "AppVersion=", version);
        if (!newIssContent.isEmpty()) {
            FileUtils.writeStringToFile(issFile, newIssContent);
            System.out.println("New version information updated! (iss)");
        }

        // RPM spec
        File rpmFile = new File(rpmPath);
        String rpmContent = FileUtils.readFileToString(rpmFile);
        String newRpmContent = replaceLine(StringUtils.split(rpmContent, '\n'), "Version: ", version);
        if (!newRpmContent.isEmpty()) {
            FileUtils.writeStringToFile(rpmFile, newRpmContent);
            System.out.println("New version information updated! (spec)");
        }

        // Java properties file
        OutputStream output = new FileOutputStream(propOutput);
        Properties prop = new Properties();
        prop.setProperty("version", version);
        prop.store(output, "Version autoupdated");
        output.close();
        System.out.println("New version information updated! (properties)");

    } catch (Exception e) {
        System.out.println("Exception ocurred, no version changed.");
        e.printStackTrace();
    }

}