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


Java FileUtils.writeStringToFile方法代码示例

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


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

示例1: outputToFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void outputToFile(int iter, Map<Measure, Double> measures){
	File evalFile = new File("./demo/Results/"+algoName+".txt");
	for (int i=0;i<iterArray.length;i++) {
		if (iter==iterArray[i]) {
			String result = getEvalInfo(measures);
			// double commas as the separation of results and configuration
			StringBuilder sb = new StringBuilder();
			String config = toString();
			sb.append(algoName).append(",").append(result).append(",,");
			if (!config.isEmpty())
				sb.append(config).append(",").append(iter);
			String evalInfo = sb.toString();

			try {
				FileUtils.writeStringToFile(evalFile,evalInfo+"\n",true);
			} catch (IOException e) {
				e.printStackTrace();
			}
			System.out.println(iter);
			System.out.println(evalInfo);

		}
	}
}
 
开发者ID:xiaojieliu7,项目名称:MicroServiceProject,代码行数:25,代码来源:IterativeRecommender.java

示例2: createServerXml

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
protected void createServerXml() {
    final String tomcatConfDir = getTomcatStagingDir().getAbsolutePath() + "/conf";

    if (ifGroupServerXmlExists()) {
        //return, one will be created as a resource
        return;
    }

    String generatedText = generateServerXml();

    LOGGER.debug("Saving template to {}", tomcatConfDir + "/" + SERVER_XML);

    File templateFile = new File(tomcatConfDir + "/" + SERVER_XML);

    try {
        FileUtils.writeStringToFile(templateFile, generatedText, Charset.forName("UTF-8"));
    } catch (IOException e) {
        throw new JvmServiceException(e);
    }
}
 
开发者ID:cerner,项目名称:jwala,代码行数:21,代码来源:ManagedJvmBuilder.java

示例3: isNew

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * Checks if a post was already save
 * @param id the ID of the post
 * @param lang the languageCode of the post
 * @return true for new posts
 */

public static boolean isNew(String id, String lang){

    File f = new File(SCRAPING_FOLDER+lang+LOG_FILE);
    if(f.exists())
        return !find(f,id);
    else {
        try {
            FileUtils.writeStringToFile(f, "id: 1,url:www.test.com\n");
            return true;
        } catch (IOException e) {
            log.error(e);
        }
    }
    return true;

}
 
开发者ID:gidim,项目名称:Babler,代码行数:24,代码来源:LogDB.java

示例4: testPull

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void testPull() throws Exception {
  // source: db2, target: db
  setupRemote();
  Git git2 = new Git( db2 );

  // put some file in the source repo and sync
  File sourceFile = new File( db2.getWorkTree(), "SomeFile.txt" );
  FileUtils.writeStringToFile( sourceFile, "Hello world" );
  git2.add().addFilepattern( "SomeFile.txt" ).call();
  git2.commit().setMessage( "Initial commit for source" ).call();
  PullResult pullResult = git.pull().call();

  // change the source file
  FileUtils.writeStringToFile( sourceFile, "Another change" );
  git2.add().addFilepattern( "SomeFile.txt" ).call();
  git2.commit().setMessage( "Some change in remote" ).call();
  git2.close();

  assertTrue( uiGit.pull() );
}
 
开发者ID:HiromuHota,项目名称:pdi-git-plugin,代码行数:22,代码来源:UIGitTest.java

示例5: mergeFiles

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * merge source file into target
 *
 * @param target
 * @param source
 */
public void mergeFiles(File target, File source) throws Throwable {
    String targetReport = FileUtils.readFileToString(target);
    String sourceReport = FileUtils.readFileToString(source);

    JSONParser jp = new JSONParser();

    try {
        JSONArray parsedTargetJSON = (JSONArray) jp.parse(targetReport);
        JSONArray parsedSourceJSON = (JSONArray) jp.parse(sourceReport);
        // Merge two JSON reports
        parsedTargetJSON.addAll(parsedSourceJSON);
        // this is a new writer that adds JSON indentation.
        Writer writer = new JSONWriter();
        // convert our parsedJSON to a pretty form
        parsedTargetJSON.writeJSONString(writer);
        // and save the pretty version to disk
        FileUtils.writeStringToFile(target, writer.toString());
    } catch (ParseException pe) {
        pe.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:usman-h,项目名称:Habanero,代码行数:30,代码来源:JSONReportMerger.java

示例6: _generate

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
protected void _generate() throws Exception {
    FileUtils.writeStringToFile(
            new File(outputPath + toMdFileName("contents")),
            getTableOfContents()
    );
    FileUtils.writeStringToFile(
            new File(outputPath + toMdFileName("introduction")),
            getIntro()
    );
    FileUtils.writeStringToFile(
            new File(outputPath + toMdFileName("Simple Properties")),
            getSimpleProperties()
    );
    FileUtils.writeStringToFile(
            new File(outputPath + toMdFileName("Sketches")),
            getSketches()
    );
    FileUtils.writeStringToFile(
            new File(outputPath + toMdFileName("Timestamps")),
            getTimestamps()
    );

    generateWalkthroughs();
    generateSimpleProperties();
}
 
开发者ID:gchq,项目名称:gaffer-doc,代码行数:27,代码来源:PropertiesWalkthroughRunner.java

示例7: upload

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@PostMapping
public @ResponseBody FileInfo upload(@RequestParam("myFile") MultipartFile file, 
        @RequestParam("message") String message) throws Exception {
    String uuid = UUID.randomUUID().toString();
    String filePath = FILES_BASE + uuid;
    FileUtils.copyToFile(file.getInputStream(), new File(filePath));
    String filename = file.getOriginalFilename();
    String contentType = file.getContentType();
    FileInfo fileInfo = new FileInfo(uuid, filename, message, contentType);
    String json = mapper.writeValueAsString(fileInfo);
    FileUtils.writeStringToFile(new File(filePath + "_meta.txt"), json, "utf-8");
    return fileInfo;
}
 
开发者ID:intuit,项目名称:karate,代码行数:14,代码来源:UploadController.java

示例8: writeCrashLogToFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * Writes a crash log to the crash log file.
 * 
 * @param e
 *            The exception.
 * @param forceExit
 *            Whether the application should get shut down.
 */
public static void writeCrashLogToFile(Exception e, boolean forceExit) {
	try {
		FileUtils.writeStringToFile(CRASH_LOG_FILE,
				e.getLocalizedMessage());
	} catch (IOException e1) {
		e1.printStackTrace();
	}

	if (forceExit)
		System.exit(-1);
}
 
开发者ID:eskalon,项目名称:ProjektGG,代码行数:20,代码来源:ErrorUtils.java

示例9: write

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public TestFile write(Object content) {
    try {
        FileUtils.writeStringToFile(this, content.toString());
    } catch (IOException e) {
        throw new RuntimeException(String.format("Could not write to test file '%s'", this), e);
    }
    return this;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:9,代码来源:TestFile.java

示例10: logWithUrlNonStatic

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void logWithUrlNonStatic(String id, String url, String lang){
    try {
        File f = dbFile;
        FileUtils.writeStringToFile(f, "id: " +id+ ", url:"+url+"\n",true);
        LogDBEntry entry = new LogDBEntry(id,url);
        db.put(entry.getId(),entry);

    } catch (IOException e) {
        log.error(e);
    }

}
 
开发者ID:gidim,项目名称:Babler,代码行数:13,代码来源:LogDB.java

示例11: write

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void write(String data) {
  try {
    FileUtils.writeStringToFile(logFile, data + Character.LINE_SEPARATOR, "UTF-8", true);
  } catch (IOException e) {
    LogManager.getLogger(getClass()).error("Failed writing to raffle log", e);
  }
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:8,代码来源:RaffleLogFile.java

示例12: writeDotConfigCache

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void writeDotConfigCache() {
	Path userConfigFolder = getUserConfigFolder();
	if (!userConfigFolder.toFile().exists()) {
		if (!userConfigFolder.toFile().mkdirs()) {
			throw new CarnotzetDefinitionException("Could not create directory [" + userConfigFolder + "]");
		}
	}
	Path localRepoPathCache = userConfigFolder.resolve("m2LocalRepoPath");
	try {
		FileUtils.writeStringToFile(localRepoPathCache.toFile(), this.localRepoPath.toString(), "UTF-8");
	}
	catch (IOException e) {
		log.warn("Could not write file [{}]", localRepoPathCache);
	}
}
 
开发者ID:swissquote,项目名称:carnotzet,代码行数:16,代码来源:MavenDependencyResolver.java

示例13: copyClassPath

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void copyClassPath(File location) {
    try {
        String content = FileUtils.readFileToString(dotClassPath, Charset.defaultCharset());
        content = content.replace("</classpath>", enginePath + "</classpath>");
        content = content.replace("..", new File("").getAbsolutePath());
        File classFile = new File(location, dotClassPath.getName());
        FileUtils.writeStringToFile(classFile, content, Charset.defaultCharset());
    } catch (IOException ex) {
        Logger.getLogger(CMProjectCreator.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:12,代码来源:CMProjectCreator.java

示例14: generateWalkthroughs

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void generateWalkthroughs(final List<AbstractWalkthrough> examples) throws Exception {
    for (final AbstractWalkthrough example : examples) {
        DocUtil.clearCache();
        FileUtils.writeStringToFile(
                new File(outputPath + toFolderName(WALKTHROUGHS_TITLE) + toMdFileName(example.getHeader())),
                example.walkthrough());
    }
}
 
开发者ID:gchq,项目名称:gaffer-doc,代码行数:9,代码来源:PropertiesWalkthroughRunner.java

示例15: _generate

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void _generate() throws Exception {
    FileUtils.writeStringToFile(
            new File(outputPath + toMdFileName("contents")),
            getTableOfContents()
    );
    for (final Example example : examples) {
        DocUtil.clearCache();
        example.run();
        FileUtils.writeStringToFile(
                new File(outputPath + toMdFileName(example.getClass().getSimpleName().replace("Example", ""))),
                example.getOutput());
    }
}
 
开发者ID:gchq,项目名称:gaffer-doc,代码行数:14,代码来源:ExampleDocRunner.java


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