当前位置: 首页>>代码示例>>Java>>正文


Java FileUtils.readFileToString方法代码示例

本文整理汇总了Java中org.apache.commons.io.FileUtils.readFileToString方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.readFileToString方法的具体用法?Java FileUtils.readFileToString怎么用?Java FileUtils.readFileToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.io.FileUtils的用法示例。


在下文中一共展示了FileUtils.readFileToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: renameEmbededImages

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * Give unique names to embedded images to ensure they aren't lost during merge
 * Update report file to reflect new image names
 *
 * @param reportFile
 */
public void renameEmbededImages(File reportFile) throws Throwable {
    File reportDirectory = reportFile.getParentFile();
    Collection<File> embeddedImages = FileUtils.listFiles(reportDirectory, new String[]{reportImageExtension}, true);

    String fileAsString = FileUtils.readFileToString(reportFile);

    for (File image : embeddedImages) {
        String curImageName = image.getName();
        String uniqueImageName = reportDirectory.getName() + "-" + UUID.randomUUID().toString() + "." + reportImageExtension;

        image.renameTo(new File(reportDirectory, uniqueImageName));
        fileAsString = fileAsString.replace(curImageName, uniqueImageName);
    }

    FileUtils.writeStringToFile(reportFile, fileAsString);
}
 
开发者ID:usman-h,项目名称:Habanero,代码行数:23,代码来源:JSONReportMerger.java

示例2: load

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * 从文件系统读取一个资源,使用当前ClassLoader读取相对路径
 * @return 资源的字符串
 * @throws Exception 资源不存在
 */
@Override
public String load() throws Exception {
    String result = null;
    try {
        String path = this.url;
        if (this.fileName != null) {
            path = path + "/" + this.fileName;
        }
        URL pathUrl = FileLoader.class.getClassLoader().getResource(path);
        result = FileUtils.readFileToString(new File(pathUrl.getPath()), "utf-8");
    } catch (Exception e) {
        throw e;
    }
    return result;
}
 
开发者ID:peterchen82,项目名称:iaac4j.aliyun,代码行数:21,代码来源:FileLoader.java

示例3: initializeGraphicalViewer

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
protected void initializeGraphicalViewer() {
	super.initializeGraphicalViewer();
	getGraphicalViewer().setRootEditPart(new ScalableFreeformRootEditPart());
	FileEditorInput inp = (FileEditorInput) getEditorInput();
	setPartName(inp.getFile().getName());
	try {
		String path = inp.getFile().getLocation().toOSString();
		String text = FileUtils.readFileToString(new File(path));
		CompositeNode node = parse(text);
		root = new CompositeEditPart(node, inp.getFile().getProject().getFullPath().toOSString());
		getGraphicalViewer().setContents(root);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:dstl,项目名称:Open_Source_ECOA_Toolset_AS5,代码行数:17,代码来源:InitAssemblyEditor.java

示例4: processFileBasedGroovyAttributes

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private static void processFileBasedGroovyAttributes(final Map<String, Object> resolvedAttributes,
                                                     final Map<String, Object> attributesToRelease,
                                                     final Matcher matcherFile, final Object[] entry) {
    try {
        LOGGER.debug("Found groovy script to execute for attribute mapping [{}]", entry[0]);
        final String script = FileUtils.readFileToString(new File(matcherFile.group(1)), StandardCharsets.UTF_8);
        final Object result = getGroovyAttributeValue(script, resolvedAttributes);
        if (result != null) {
            LOGGER.debug("Mapped attribute [{}] to [{}] from script", entry[0], result);
            attributesToRelease.put(entry[0].toString(), result);
        } else {
            LOGGER.warn("Groovy-scripted attribute returned no value for [{}]", entry[0]);
        }
    } catch (final IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:ReturnMappedAttributeReleasePolicy.java

示例5: openFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
* 
* @Title: openFile 
* @Description: open file to get file content 
* @param @param parent
* @param @param fc
* @param @return 
* @return String
* @throws
 */
public static String openFile(Component parent, JFileChooser fc)
{
    String content = StringUtils.EMPTY;
    int retVal = fc.showOpenDialog(parent);
    if (JFileChooser.APPROVE_OPTION != retVal)
    {
        return content;
    }

    try
    {
        File sf = fc.getSelectedFile();
        content = FileUtils.readFileToString(sf, Charsets.UTF_8.getCname());
    }
    catch(IOException e)
    {
        FormatView.getView().getStat().setText("Failed to read file: " + e.getMessage());
    }

    return content;
}
 
开发者ID:wisdomtool,项目名称:formatter,代码行数:32,代码来源:FormatUtil.java

示例6: testTaskCreate

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test(timeout=10000)
public void testTaskCreate() throws IOException {
  File batch = new File(TEST_DIR, "testTaskCreate.cmd");
  File proof = new File(TEST_DIR, "testTaskCreate.out");
  FileWriter fw = new FileWriter(batch);
  String testNumber = String.format("%f", Math.random());
  fw.write(String.format("echo %s > \"%s\"", testNumber, proof.getAbsolutePath()));
  fw.close();
  
  assertFalse(proof.exists());
  
  Shell.execCommand(Shell.WINUTILS, "task", "create", "testTaskCreate" + testNumber, 
      batch.getAbsolutePath());
  
  assertTrue(proof.exists());
  
  String outNumber = FileUtils.readFileToString(proof);
  
  assertThat(outNumber, containsString(testNumber));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:TestWinUtils.java

示例7: getCommityInfoByCName

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public CommityInfo getCommityInfoByCName(String CName) throws IOException {

        CommityInfo re = commityManageDao.getCommmityInfoByCName(CName);
        File imgPath = new File(StaticVar.getToFilePath() + re.getCHeadImg());
        String imgEncode = FileUtils.readFileToString(imgPath, StaticVar.getDecodeFileSet());
        re.setCImgObj(imgEncode);
        return re;
    }
 
开发者ID:okingjerryo,项目名称:WeiMusicCommunity-server,代码行数:9,代码来源:CommityManageService.java

示例8: importSessionFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void importSessionFile() throws Exception {
  StvsRootModel importedSession = ImporterFacade.importSession(new File(XmlSessionImporter.class
          .getResource("session_valid_1.xml").toURI().getPath()),
      ImporterFacade.ImportFormat.XML, new GlobalConfig(), new History());
  String code = FileUtils.readFileToString(new File(StvsApplication.class.getResource
      ("testSets/valid_1/code_valid_1.st").toURI()), "utf-8");
  Assert.assertEquals(TestUtils.removeWhitespace(code), TestUtils.removeWhitespace(importedSession.getScenario()
      .getCode().getSourcecode()));
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:11,代码来源:ImporterFacadeTest.java

示例9: getDeployScript

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void getDeployScript() throws Exception {
    File targetFile = new File(targetDir + "/output/scripts/", FILEPRAEFIX_DEPLOY + appName +
        FILESUFFIX_DEPLOY);
    String deployScript = FileUtils.readFileToString(targetFile);
    String expectedOutput = String.format("#!/bin/sh\nsource util/*\ncheck \"cf\"\n%smy_db\n%s%s%s%s\n",
        CLI_CREATE_SERVICE_DEFAULT, CLI_PUSH, appName, CLI_PATH_TO_MANIFEST, MANIFEST_NAME);

    assertEquals(expectedOutput, deployScript);
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:11,代码来源:CloudFoundryPluginTest.java

示例10: doProcess

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void doProcess(Options options) {
    this.noAct = options.getNoAct().isSet();
    this.online = options.getOnline().isSet();
    String fileName = options.getFileName().getValue();
    File configFile = new File(fileName);
    try {
        String config = FileUtils.readFileToString(configFile, "UTF-8");
        doProcess(config, noAct, online);
    } catch (IOException ex) {
        LOGGER.error("Failed to read config file.", ex);
    }
}
 
开发者ID:hylkevds,项目名称:SensorThingsProcessor,代码行数:13,代码来源:ProcessorWrapper.java

示例11: generateMetadataForIdp

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * Displays the identity provider metadata.
 * Checks to make sure metadata exists, and if not, generates it first.
 *
 * @param response servlet response
 * @throws IOException the iO exception
 */
@GetMapping(path = SamlIdPConstants.ENDPOINT_IDP_METADATA)
public void generateMetadataForIdp(final HttpServletResponse response) throws IOException {
    final File metadataFile = this.metadataAndCertificatesGenerationService.performGenerationSteps();
    final String contents = FileUtils.readFileToString(metadataFile, StandardCharsets.UTF_8);
    response.setContentType(CONTENT_TYPE);
    response.setStatus(HttpServletResponse.SC_OK);
    try (PrintWriter writer = response.getWriter()) {
        LOGGER.debug("Producing metadata for the response");
        writer.write(contents);
        writer.flush();
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:20,代码来源:SamlMetadataController.java

示例12: getConfiguration

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * return the configuration JSON object.
 *
 * @return the configuration JSON object.
 * @throws IOException
 *             if an error occurs.
 */
public static JSONObject getConfiguration() {
	try {
		final JSONObject controllerNodeConfig = new JSONObject(
				FileUtils.readFileToString(CONFIG_FILE, Charset.defaultCharset()));
		final int nonce = ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE);
		controllerNodeConfig.put(ConfigurationUtil.NONCE, nonce);
		return controllerNodeConfig;
	} catch (final IOException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:19,代码来源:ConfigurationUtil.java

示例13: loadConfigFromFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private RateLimitingSettings loadConfigFromFile(String filename, String filterKey)
		throws JsonProcessingException, IOException {
	logger.info("Loading configuration from file " + filename);
	File file = new File(filename);
	if (!file.exists())
		throw new IllegalArgumentException("File " + filename + " doesn't exist!");

	String raw = FileUtils.readFileToString(file);
	return fromString(raw, filterKey);
}
 
开发者ID:akharchuk,项目名称:rate-limiting,代码行数:11,代码来源:ConfigurationLoader.java

示例14: writePageDoc

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * 
 * @param order
 * @param rootDoc
 * @param aggregateRecords
 * @throws FatalIndexerException
 */
private void writePageDoc(int order, SolrInputDocument rootDoc, boolean aggregateRecords) throws FatalIndexerException {
    String iddoc = pageDocOrderIddocMap.get(order);
    SolrInputDocument doc = load(iddoc);
    if (doc != null) {
        // doc.setField(SolrConstants.ORDER, newOrder); // make sure order starts at 1 in the end
        {
            Path xmlFile = Paths.get(tempFolder.toAbsolutePath().toString(), new StringBuilder().append(iddoc).append("_").append(
                    SolrConstants.FULLTEXT).toString());
            if (Files.isRegularFile(xmlFile)) {
                try {
                    String xml = FileUtils.readFileToString(xmlFile.toFile(), "UTF8");
                    doc.addField(SolrConstants.FULLTEXT, xml);

                    // Add the child doc's FULLTEXT values to the SUPERFULLTEXT value of the root doc
                    if (aggregateRecords) {
                        // sbSuperDefault.append('\n').append(doc.getFieldValue(SolrConstants.FULLTEXT));
                        rootDoc.addField(SolrConstants.SUPERFULLTEXT, (doc.getFieldValue(SolrConstants.FULLTEXT)));
                    }
                    logger.debug("Found FULLTEXT for: {}", iddoc);
                } catch (IOException e) {
                    logger.error(e.getMessage(), e);
                }
            }
        }
        checkAndAddAccessCondition(doc);
        if (!solrHelper.writeToIndex(doc)) {
            logger.error(doc.toString());
        }
        // newOrder++;
    } else {
        logger.error("Could not find serialized document for IDDOC: {}", iddoc);
    }
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:41,代码来源:SerializingSolrWriteStrategy.java

示例15: renderIndex

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void renderIndex() throws Exception {
    //exec
    renderer.renderIndex("index.html");

    //validate
    File outputFile = new File(destinationFolder, "index.html");
    Assert.assertTrue(outputFile.exists());

    // verify
    String output = FileUtils.readFileToString(outputFile, Charset.defaultCharset());
    for (String string : getOutputStrings("index")) {
        assertThat(output).contains(string);
    }
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:16,代码来源:AbstractTemplateEngineRenderingTest.java


注:本文中的org.apache.commons.io.FileUtils.readFileToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。