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


Java FileUtils.writeLines方法代码示例

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


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

示例1: generatePCHFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void generatePCHFile(List<String> headers, File headerFile) {
    if (!headerFile.getParentFile().exists()) {
        headerFile.getParentFile().mkdirs();
    }

    try {
        FileUtils.writeLines(headerFile, CollectionUtils.collect(headers, new Transformer<String, String>() {
            @Override
            public String transform(String header) {
                if (header.startsWith("<")) {
                    return "#include ".concat(header);
                } else {
                    return "#include \"".concat(header).concat("\"");
                }
            }
        }));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:21,代码来源:PCHUtils.java

示例2: generateBundleListCfg

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void generateBundleListCfg(AppVariantContext appVariantContext) throws IOException {
    List<String> bundleLists = AtlasBuildContext.awbBundleMap.keySet().stream().map(key -> {
        return "lib/armeabi/" + key;
    }).sorted().collect(Collectors.toList());
    File outputFile = new File(appVariantContext.getScope().getGlobalScope().getOutputsDir(), "bundleList.cfg");
    FileUtils.deleteQuietly(outputFile);
    outputFile.getParentFile().mkdirs();
    FileUtils.writeLines(outputFile, bundleLists);

    appVariantContext.bundleListCfg = outputFile;
    //Set the bundle dependencies

    List<BundleInfo> bundleInfos = new ArrayList<>();
    AtlasBuildContext.awbBundleMap.values().stream().forEach(new Consumer<AwbBundle>() {
        @Override
        public void accept(AwbBundle awbBundle) {
            bundleInfos.add(awbBundle.bundleInfo);
        }
    });

}
 
开发者ID:alibaba,项目名称:atlas,代码行数:22,代码来源:PrepareBundleInfoTask.java

示例3: bufferOrStoreTweet

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private synchronized void bufferOrStoreTweet(Tweet miniTweet) {
	bufferedTweets.add(miniTweet);
	if (bufferedTweets.size() >= bufferedTweetSize) {
		File tweetFile = new File(outputFileLocation);
		try {
			logger.info("About to persist : "+bufferedTweetSize+" tweets");
			List<String> outputTweets = new ArrayList<String>();
			for(Tweet tweet : bufferedTweets){
				outputTweets.add(tweet.getAsJson(tweet));
			}
			FileUtils.writeLines(tweetFile, "UTF-8", (Collection<String>) outputTweets, "\n", true);
		} catch (IOException e) {
			logger.error(e);
		}
		bufferedTweets = new ArrayList<Tweet>();
	}
}
 
开发者ID:shubhamsharma04,项目名称:jsonTweetDownload,代码行数:18,代码来源:CustomStatusListener.java

示例4: main

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * 使用common io批量将java编码从GBK转UTF-8
 * 
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
	// GBK编码格式源码路径
	 String srcDirPath = "D:\\Java\\gbk";
	// 转为UTF-8编码格式源码路径
	String utf8DirPath = "D:\\Java\\utf8";

	// 获取所有java文件
	Collection<File> javaGbkFileCol = FileUtils.listFiles(new File(srcDirPath), new String[] { "java" }, true);
	for (File javaGbkFile : javaGbkFileCol) {
		boolean bUtf8Encoding = isUTF8(javaGbkFile.getAbsolutePath().substring(srcDirPath.length()));
		if (!bUtf8Encoding) {
			// UTF8格式文件路径
			String utf8FilePath = utf8DirPath + javaGbkFile.getAbsolutePath().substring(srcDirPath.length());
			// 使用GBK读取数据,然后用UTF-8写入数据
			FileUtils.writeLines(new File(utf8FilePath), "UTF-8", FileUtils.readLines(javaGbkFile, "GBK"));
		}
		System.out.println();
	}
	System.out.println("success.");
}
 
开发者ID:fochess,项目名称:GBKToUTF8,代码行数:27,代码来源:GbkToUtf8.java

示例5: write

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public boolean write(@NotNull Configuration configuration) {
    List<String> lines = new ArrayList<>();

    for (Property property : configuration.properties.keySet()) {
        lines.add(property + "=" + configuration.get(property, ""));
    }

    try {
        FileUtils.writeLines(new File(path), lines);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

    return true;
}
 
开发者ID:andreyfomenkov,项目名称:green-cat,代码行数:17,代码来源:ConfigurationWriter.java

示例6: writeProperties

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void writeProperties(Map<String, String> map, File file) {
    file.delete();
    file.getParentFile().mkdirs();
    try {
        List<String> lines = new ArrayList<String>();
        for (String key : map.keySet()) {
            lines.add(key + "=" + map.get(key));
        }
        FileUtils.writeLines(file, lines);
    } catch (IOException e) {
        e.printStackTrace();
    }

}
 
开发者ID:alibaba,项目名称:atlas,代码行数:15,代码来源:PreparePackageIdsTask.java

示例7: saveToFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * Save block list into a file.
 *
 * @param f File to save to
 */
public void saveToFile(File f) {
    try {
        FileUtils.writeLines(f, blocks);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:BurnyDaKath,项目名称:OMGPI,代码行数:13,代码来源:BlockInfo.java

示例8: modifyFieldValue

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * relace const string in dexFile
 *
 * @param dexFile
 * @param outDexFile
 * @param orgFieldValue
 * @param newFieldValue
 * @return
 */
public static boolean modifyFieldValue(File dexFile, File outDexFile, String orgFieldValue,
                                       String newFieldValue) throws IOException, RecognitionException {
    File smaliFolder = new File(outDexFile.getParentFile(), "smali");
    if (smaliFolder.exists()) {
        FileUtils.deleteDirectory(smaliFolder);
    }
    smaliFolder.mkdirs();
    boolean disassembled = SmaliUtils.disassembleDexFile(dexFile, smaliFolder);
    if (disassembled) {
        Collection<File> smaliFiles = FileUtils.listFiles(smaliFolder, new String[]{"smali"}, true);
        for (File smaliFile : smaliFiles) {
            List<String> lines = FileUtils.readLines(smaliFile);
            for (int index = 0; index < lines.size(); index++) {
                String line = lines.get(index);
                String newLine = StringUtils.replace(line, "\"" + orgFieldValue + "\"", "\"" + newFieldValue + "\"");
                lines.set(index, newLine);
            }
            FileUtils.writeLines(smaliFile, lines);
        }

        //转换为dex文件
        boolean assembled = SmaliUtils.assembleSmaliFile(smaliFolder, outDexFile);
        if (assembled) {
            FileUtils.deleteDirectory(smaliFolder);
            return true;
        }
    }
    return false;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:39,代码来源:PatchFieldTool.java

示例9: copiedCorrectFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void copiedCorrectFile() throws IOException {
  List<String> randomData = new ArrayList<>();
  randomData.add("foo");
  randomData.add("baz");
  File source = temporaryFolder.newFile("test.txt");
  FileUtils.writeLines(source, randomData);
  File destination = temporaryFolder.newFolder();
  SchemaCopier copier = new SchemaCopier(new HiveConf(), new HiveConf());
  File copy = new File(copier.copy(source.toString(), destination.toString()).toString());
  assertTrue(FileUtils.contentEquals(source, copy));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:13,代码来源:SchemaCopierTest.java

示例10: print

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void print() {
    String fileName = fileRootPath + "/" + StringUtils.replace(sourcePackageName.toLowerCase(), ".", "/") + "/"
                      + className + ".java";
    File javaFile = new File(fileName);
    List<String> fileData = collectFileData();
    if (fileData != null) {
        try {
            FileUtils.writeLines(javaFile, "UTF-8", fileData);
        } catch (IOException e) {
            throw new IllegalArgumentException("can not write file to" + fileName, e);
        }
    }
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:14,代码来源:AbstractPrint.java

示例11: configureSTIBuildFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void configureSTIBuildFile(Map<String, String> env) {
	try {
		Path envFile = path.resolve(ENV_FILE_LOCATION);
		FileUtils.writeLines(
				envFile.toFile(),
				env.entrySet().stream()
						.map(entry -> entry.getKey() + "=" + entry.getValue())
						.collect(Collectors.toList()), true);
		repo.add().addFilepattern(ENV_FILE_LOCATION).call();
	} catch (IOException | GitAPIException ex) {
		LOGGER.error("Error when configuring STI", ex);
		throw new IllegalStateException("Error when configuring STI", ex);
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:15,代码来源:GitProject.java

示例12: write

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void write(final Map<String, String> items) {
    final List<String> lines = Lists.newArrayList();
    for (final Entry<String, String> item : items.entrySet()) {
        lines.add(item.getKey() + " = " + item.getValue());
    }

    try {
        FileUtils.writeLines(new File(mConfigFilePath), lines);
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:chncwang,项目名称:laozhongyi,代码行数:13,代码来源:HyperParameterConfig.java

示例13: ASSSubtitleConverter

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
ASSSubtitleConverter(File folder, String xmlString, SubtitleInfo subtitle) {
    Document doc = loadXMLFromString(xmlString);
    doc.getDocumentElement().normalize();

    handleScriptBlock(doc.getDocumentElement());

    NodeList childNodes = doc.getDocumentElement().getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node item = childNodes.item(i);
        String nodeName = item.getNodeName();
        switch (nodeName) {
            case "styles":
                handleStylesBlock((Element)item);
                break;
            case "events":
                handleEventsBlock((Element)item);
                break;
            default:
                System.out.println("unknown subtitle block "+nodeName);
                break;
        }
        assLines.add("");
    }

    try {
        FileUtils.writeLines(new File(folder, subtitle.id+".ass"), assLines);
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println("An error occured while attempting to write a subtitle file");
        System.exit(-2);
    }

}
 
开发者ID:clienthax,项目名称:Crunched,代码行数:34,代码来源:ASSSubtitleConverter.java

示例14: schrijfSteekproefBestand

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
public void schrijfSteekproefBestand(final MaakSelectieResultaatTaak taak, final List<String> regelsInSteekproef) throws IOException {
    final Path baseFolder = getSelectietaakResultaatPath(taak.getSelectietaakId(), taak.getDatumUitvoer());
    final String steekproefBestand = String.format("/steekproef_%s_%s_%s.txt",
            taak.getDatumUitvoer(), taak.getDienstId(), taak.getSelectietaakId());
    final Path outFile = Paths.get(baseFolder.toString(), steekproefBestand);
    final List<String> decodedList = regelsInSteekproef.stream()
            .map(s -> Base64.getDecoder().decode(s))
            .map(s -> new String(s, StandardCharsets.UTF_8)).
                    collect(Collectors.toList());
    FileUtils.writeLines(outFile.toFile(), StandardCharsets.UTF_8.name(), decodedList);
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:13,代码来源:SelectieFileServiceImpl.java

示例15: writeLines

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void writeLines(File file, Collection<?> lines) {
    try {
        FileUtils.writeLines(file, lines);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:8,代码来源:FileUtilsCobra.java


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