當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。