本文整理汇总了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);
}
}
}
示例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);
}
}
示例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;
}
示例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() );
}
示例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();
}
}
示例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();
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
示例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());
}
}